1

I've installed the Haskell platform on my mac (OSX lion), and ghci is running great.

Now I've created a haskell-file, stored on my "desk." How can I call it from this directory?

Example:

Prelude> :load datei.hs
[1 of 1] Compiling Main             ( datei.hs, interpreted )

datei.hs:1:7: parse error on input `\'
Failed, modules loaded: none.

datei.hs:

let fac n = if n == 0 then 1 else n * fac (n-1)

Why do I get this?

1
  • 2
    there is no ` \ ` in what you linked. There must be more input. And haskell isn't an ML you don't need to let to declare functions. Just fac 0 = if n == 0 then 1 else n * fac (n-1) will work. But most people would write it like this fac n = product [1..n] or fac 0 = 1 fac n = n * fac (n-1) Commented Nov 27, 2013 at 21:09

3 Answers 3

1

Use the OSX terminal to reach your desktop and invoke yourfile.hs using ghci:

cd ~/Desktop
ghci yourfile.hs

edit:

As stated in the comments, the error message you're seeing above is warning you that the character \ exists at an unexpected location in the source code.

Since that character does not exist in the line of code you posted, there must be more to datei.hs. We need to see the rest of your source code before we can help.

Sign up to request clarification or add additional context in comments.

Comments

1

If you saved your program with TextEdit, it's very possible that you're seeing a '\' character because you're saving it as an RTF file (TextEdit's default). Hit Ctrl-shift-t to convert it into a plain text file.

Comments

0

If your already in ghci you can use ':cd /path/to/file' as well.

Here is a good thread discussing let.

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.