No title

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
-- I have this record, for which I create lenses
data FileInfo = FileInfo
  {
    _modifyTime :: String
    , _changeTime :: String
  } deriving (Show,Read,Generic)
makeLenses ''FileInfo

-- I have a function which does the same things, only depending on the getter that is used
import qualified FileInfo as FI
isUserMoreRecent :: a -> Maybe Time -> FI.FileInfo -> FI.FileInfo -> Bool
isUserMoreRecent getter lastSynchroTime ufi mfi = isRecent || isMoreRecentThanLastSynchro
  where
    isRecent = (view getter ufi) < (view getter mfi)
    isMoreRecentThanLastSynchro = (view getter ufi) < lastSynchroTime

-- I try to use it this way in the code of a local function
     where
        predicateModif :: FileInfo -> Bool
        predicateModif  = isUserMoreRecent FI.modifyTime lastSynchroTime ufi
        predicateChange :: FileInfo -> Bool
        predicateChange = isUserMoreRecent FI.changeTime lastSynchroTime ufi

-- unfortunately it doesnt compile
-- I was going to switch to the record field name to pass as argument, but I'd prefer trying to understand why using the lens getters did not work
/src/MasterAsk.hs:123:40: error:
     Ambiguous type variable f1 arising from a use of FI.modifyTime
      prevents the constraint (Functor f1) from being solved.
      Probable fix: use a type annotation to specify what f1 should be.
      These potential instances exist:
        instance Functor (Either a) -- Defined in ‘Data.Either’
        instance Functor Identity -- Defined in ‘Data.Functor.Identity’
        instance Functor IO -- Defined in ‘GHC.Base’
        ...plus 9 others
        ...plus 119 instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
     In the first argument of isUserMoreRecent, namely
        FI.modifyTime
      In the expression:
        (isUserMoreRecent FI.modifyTime lastSynchroTime ufi)
      In an equation for predicateModif:
          predicateModif = (isUserMoreRecent FI.modifyTime lastSynchroTime ufi)