0

I wrote this code (based on the AddressBook example in PureScript by Example)

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!"

but I get an error

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

Edit:: I tried

let output = map showEntry (findEntry "foo1" "bar1" addressBook)
log output

and now I get error

at src/Main.purs line 52, column 7 - line 52, column 13

  Could not match type

    Maybe String

  with type

    String
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373

1 Answers1

1

Strings can be logged, so you have to convert output to a string before passing it to log:

log (show output)

or just

logShow output
stholzm
  • 3,395
  • 19
  • 31