Hi
I am going through the book and having some issues with the AddressBook
section of chapter 3.
I run spago repl and type:
> import Data.AddressBook
> address = { street: "123 Fake St.", city: "Faketown", state: "CA" }
> showAddress address
"123 Fake St., Faketown, CA"
> entry = { firstName: "John", lastName: "Smith", address: address }
> showEntry entry
"Smith, John: 123 Fake St., Faketown, CA"
-
Now, if I try to create a new book with
book = List entry
I get an errorUnknown data constructor List
â I believe this is because I should not build a new AddressBook that way, but please confirm. It is not clear from the book how I use this type/create new variables of this type (unless with the below point 2.?)⌠-
I can construct a new book by doing
emptyBook = book
and then add entries by doingbook1 = insertEntry entry book
.
Because of immutable data, I assume I need to create a new book with a new name everytime? -
The book states:
> :type insertEntry entry
AddressBook -> AddressBook
And this should work if I type it in my repl, since we have âtype aliasedâ (type synonym?) List Entry
with AddressBook
in Main.purs
However I get:
> :type insertEntry entry
List
{ address :: { city :: String
, state :: String
, street :: String
}
, firstName :: String
, lastName :: String
}
-> List
{ address :: { city :: String
, state :: String
, street :: String
}
, firstName :: String
, lastName :: String
}
I understand these are equivalent but is it intended?
â Edit
This is also giving me a headache
> findEntry "John" "Smith"
Error found:
in module $PSCI
at <internal>:0:0 - 0:0 (line 0, column 0 - line 0, column 0)
No type class instance was found for
Data.Show.Show (List
{ address :: { city :: String
, state :: String
, street :: String
}
, firstName :: String
, lastName :: String
}
-> Maybe
{ address :: { city :: String
, state :: String
, street :: String
}
, firstName :: String
, lastName :: String
}
)
while applying a function eval
of type Eval t1 => t1 -> Effect Unit
to argument it
while checking that expression eval it
has type Effect t0
in value declaration $main
where t0 is an unknown type
t1 is an unknown type
Being the definition findEntry firstName lastName = head <<< filter filterEntry
shouldnât it work with the above args?