我编写了这段代码(基于PureScript中的AddressBook示例)
findEntry :: String -> String -> AddressBook -> Maybe Entry
findEntry firstName lastName = head <<< filter filterEntry
where
filterEntry :: Entry -> Boolean
filterEntry entry = entry.firstName == firstName && entry.lastName == lastName
main :: forall e. Eff (console :: CONSOLE | e) Unit
main = do
let address1 = {street: "123 Fake St.", city: "Faketown", state: "CA"}
let address2 = {street: "234 Fake St.", city: "Faketown", state: "CA"}
let entry1 = {firstName: "foo1", lastName: "bar1", address: address1}
let entry2 = {firstName: "foo2", lastName: "bar2", address: address2}
let addressBook = insertEntry entry2 (insertEntry entry1 emptyBook)
let output = map showEntry (findEntry "foo1" "bar1" addressBook)
map log (output)
log "Hello Sailor!"
但是我收到了错误
Compiling Main
Error found:
in module Main
at src/Main.purs line 53, column 3 - line 53, column 7
Could not match type
Eff
( console :: CONSOLE
| t1
)
with type
Maybe
while trying to match type Eff
( console :: CONSOLE
| t1
)
Unit
with type Maybe t0
while checking that expression log "Hello Sailor!"
has type Maybe t0
in value declaration main
where t0 is an unknown type
t1 is an unknown type
编辑::我试过
let output = map showEntry (findEntry "foo1" "bar1" addressBook)
log output
现在我收到错误
at src/Main.purs line 52, column 7 - line 52, column 13
Could not match type
Maybe String
with type
String
答案 0 :(得分:1)
可以记录字符串,因此您必须先将output
转换为字符串,然后再将其传递给log
:
log (show output)
或只是
logShow output