1

I have been reading "learn you haskell for great good", and in this part:

"let’s put a string that represents a person in a script and then load that script in GHCi:

mysteryDude = "Person { firstName =\"Michael\"" ++
                      ", lastName =\"Diamond\"" ++ 
                      ", age = 43}"

We wrote our string across several lines like this for increased readability. If we want to read that string, we need to tell Haskell which type we expect in return:

ghci> read mysteryDude :: Person

But I don't know how to create the 'script', it's in mysteryDude.hs file, and then I need to load it with >:l mysteryDude.hs Or what. But I tried it and I got this error:

*Main> read mysteryDude.hs :: Person

<interactive>:50:23: error:
    Not in scope: type constructor or class ‘Person’
*Main> read mysterDude.hs :: Person

I see that in the web here, they change it, and don't do it in the same way, so, maybe it's an error.

But even if in this example is an error I would like to know how to write a 'script' and load data from it.

4
  • Did you define data Person inside mysteryDude.hs? Commented Aug 10, 2018 at 12:24
  • No, it's in another file, in person.hs Commented Aug 10, 2018 at 12:26
  • Does mysteryDude.hs import it? Commented Aug 10, 2018 at 12:27
  • no... I starting to see the problem Commented Aug 10, 2018 at 12:28

1 Answer 1

2

From comments I deduced the problem. :l in ghci forgets all previous :ls and all definitions that you made in REPL. You should either:

  • Make files import each other (avoiding import cycles). Filenames and module names must match.
  • import both files in ghci. Again, module names should match the names of files.
  • Make all your definitions in REPL's toplevel. You may use multiline snippets surrounding them by :{ :}. Not recommended tho
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.