While doing exercises of chapter 3 of the Purescript by Example book was puzzled by this:
The exercise is to write an isInBook :: String -> String -> AddressBook -> Boolean
findEntryByName :: String -> String -> AddressBook -> Maybe Entry
findEntryByName first last = head <<< filter
\entry -> entry.firstName == first && entry.lastName == last
isSomething :: forall a. Maybe a -> Boolean
isSomething a = case a of
Nothing -> false
Just _ -> true
AddressBook :: List Entry
, and this does what I want it to do. (on a sidenote, is there a common name for isSomething
? It seems like a common function to want; a proposition whether something isn't Nothing
)
But this doesn't compile:
isInBook = isSomething <<< findEntryByName
And after some searching I found that this does:
isInBook fist last = isSomething <<< findEntryByName first last
Why? I found the compile error not terribly helpful, but that may be my inexperience:
Could not match type
Function String
with type
Maybe
while trying to match type String
-> List
{ address :: ...
, firstName :: String
, lastName :: String
}
-> Maybe
{ address :: ...
, firstName :: String
, lastName :: String
}
with type Maybe t1
while checking that expression findEntryByName
has type t0 -> Maybe t1
in value declaration isInBook
where t0 is an unknown type
t1 is an unknown type