Using the let.hs File

I use Notepad ++ and WinGHCi to do the homework, and I need to define a small "database". The format is arbitrary, and I don’t think where I am mistaken. Anyway, here is what I use in the * .hs file:

let studentDB = [ ("sally", ["cpsc110", "cpsc312", "cpsc204"]), ("jim", ["cpsc110", "cpsc313"]), ("bob", ["cpsc121", "cpsc303", "cpsc212"]), ("frank", ["cpsc110", "cpsc212", "cpsc204"]), ("billy", ["cpsc312", "cpsc236"]), ("jane", ["cpsc121"]), ("larry", ["cpsc411", "cpsc236"]) ] 

WinGHCi gives me this error: a1.hs: 118: 1: parsing error (possibly indented incorrectly)

I tried messing with the tuple tabs or placing my brackets on different lines, but couldn't get anything to work. I thought something less would help me track the error, so I did this instead:

 let s = [] 

But that gave me the same error. Is this an indented error, possibly due to some fancy Notepad ++ behavior? Or is my Haskell wrong? Thanks.

+7
source share
1 answer

I think you think the contents of the * .hs file are similar to what you can type in ghci. This is not true. When you enter text in ghci, you effectively enter text in the do block. So the following syntax is correct:

 main = do let s = [] -- do more stuff 

However, at the top level of the * .hs file, everything is different. Let construct actually

 let s = [] in codeThatReferencesS 

If you want to define a top-level binding, just say

 s = [] 
+14
source

All Articles