Home Download Buy Blog Forum Support

Run Haskell

Run Haskell

Postby rongreen on Sun Jul 06, 2014 8:19 pm

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 meant `min' (imported from Prelude)

Can someone help a newb?
rongreen
 
Posts: 2
Joined: Sun Jul 06, 2014 8:10 pm

Re: Run Haskell

Postby bordaigorl on Mon Jul 07, 2014 1:03 pm

Suppose your Haskell file contains the following

Code: Select all
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

Code: Select all
{
   "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

Code: Select all
{
    "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.
bordaigorl
 
Posts: 8
Joined: Sun Mar 16, 2014 2:24 pm

Re: Run Haskell

Postby rongreen on Mon Jul 07, 2014 10:06 pm

Thank you
rongreen
 
Posts: 2
Joined: Sun Jul 06, 2014 8:10 pm


Return to General Discussion

Who is online

Users browsing this forum: Google [Bot] and 10 guests