Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lacks an accompanying binding - What does it mean? How it works?

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

like image 792
Optimight Avatar asked Jul 27 '12 07:07

Optimight


2 Answers

You need to provide an implementation for phoneBook.

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

like image 175
brano Avatar answered Nov 05 '22 11:11

brano


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

like image 1
Jonas Duregård Avatar answered Nov 05 '22 12:11

Jonas Duregård