I am practising from LYAH.
phoneBook.hs file contains following code:
phoneBook :: [(String, String)]
While trying to compile the above-mentioned code I am getting following error:
*Main> :load "/home/optimight/phoneBook.hs" [1 of 1] Compiling Main ( /home/optimight/phoneBook.hs, interpreted )
/home/optimight/phoneBook.hs:1:1: The type signature for `phoneBook' lacks an accompanying binding Failed, modules loaded: none.
Question added after brano's answer and subsequent comment to this answer: How do we provide implementation for above-mentioned type signature?
If I add this :
type phoneBook = [(String, String)]
I am getting following error:
Prelude> :load "/home/optimight/phoneBook.hs" [1 of 1] Compiling Main ( /home/optimight/phoneBook.hs, interpreted )
/home/optimight/phoneBook.hs:2:6: Malformed head of type or class declaration: phoneBook Failed, modules loaded: none
You need to provide an implementation for phoneBook.
phoneBook :: [(String, String)]
is just the signature.
If you want to declare a type, it must have initial upper case i.e. type PhoneBook = [(String, String)]
.
If you want to declare a function then you need to provide either just its definition (the binding) or both its definition and its type signature. The minimal effort to compile your code is:
phoneBook :: [(String, String)]
phoneBook = undefined
Then you can replace undefined
with any value of type [(String, String)]
e.g. [("Person","Number")]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With