Question

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

Was it helpful?

Solution

You need to provide an implementation for phoneBook.

phoneBook :: [(String, String)] is just the signature.

OTHER TIPS

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")].

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top