Sublime Forum

Run Haskell

#1

New to ST and Haskell. Downloaded ST3 yesterday. Created small Ruby file. Set build to automatic. hit command-B. File runs perfectly. Created small Haskell file from Chapter 1 of “Learn you some Haskell”. Contains 3 small functions. Load and run on command line using GHCI. No Problem. Try to run from inside ST3 I get the following output:
/Users/rongreen/Desktop/baby.hs:1:33:
Not in scope: main' Perhaps you meantmin’ (imported from Prelude)

Can someone help a newb?

0 Likes

#2

Suppose your Haskell file contains the following

doubleUs x y = doubleMe x + doubleMe y
doubleSmallNumber' x = (if x > 100 then x else x*2) + 1

What would you expect “Build” to do?
Running this file does not have a definite meaning: running which function? With which arguments?
What it does depends on the contents of your “Haskell.sublime-build” file which by default is

{ "shell_cmd": "runhaskell \"$file\"", "file_regex": "^(...*?):([0-9]*):?([0-9]*)", "selector": "source.haskell" }

Now, runhaskell is a script that executes the “main” function, when defined in your file.
Look in the docs for how to write the main function and you should be ready to go.

In my configuration I put a custom “Haskell.sublime-build” file in my User directory with

{ "selector": "source.haskell", "working_dir": "$file_path", "cmd": "gnome-terminal","-x","ghci", "$file"] }

which, under a gnome-like environment will launch a console running ghci loaded with your script so you can play with it.

0 Likes

#3

Thank you

0 Likes