Search code examples
parsinghaskelljupyterghcilet

Haskell parse error with ghci with 'let'


I've been sitting around here for quite some time now and my problem just won't solve by googling, try and error. I've got the following code snippet:

data Prozess = Prozess { pid :: Int, arrival :: Int, computing :: Int } deriving (Show)

let idle = Prozess{pid=1, arrival=5, computing=10}

So I tried to compile it with ghci, but it's keep giving me a "parse error (possibly incorrect indentation or mismatched brackets)" at the "let idle ..."-line. Weird thing is, I tried compiling this using our Jupyter-Server and that seems to work nicely. Also, if I compile it without the "let"-line and input the -exact- same line afterwards via Terminal in *Main>, it's working fine too.

So what's wrong with ghci? Think I'm losing my mind over this.


Solution

  • Your let isn't in any function is it?

    If you're just defining a global "constant", you just go:

    idle :: Prozess
    idle = Prozess{pid=1, arrival=5, computing=10}
    

    Also, note that you don't need the record notation. You can swap that for:

    idle = Prozess 1 5 10