1

I am trying to code using a functional programming langauge called Elm. From various sources, I received recommendations to use Sublime and Cygwin. I successfully set up Cygwin such that I can enter elm commands and it works. But I would think there should be some way to set up Sublime such that I can write the code in Sublime.

My Question

Can Sublime Text 2 run Elm by itself? Do I need to link Cygwin to it somehow to permit Sublime to run Elm code? I just want Sublime to be able to accept the commands I input like any coding interface. How can I set up sublime to run the Elm commands like Cygwin does?

For reference, here's Elm's website: http://elm-lang.org/

MattDMo
  • 100,794
  • 21
  • 241
  • 231
Stan Shunpike
  • 2,165
  • 3
  • 20
  • 32
  • 1
    Interesting that you were advised to use Cygwin. Wouldn't it be easier to use the [windows installer for Elm](http://elm-lang.org/Install.elm)? – Apanatshka Jan 12 '15 at 09:04
  • I used the Windows Installer. Seemingly, Cygwin can then access Elm just by typing elm-repl into the Cygwin command input interface. So no problem installing elm or accessing it from Cygwin But I haven't been able to get Sublime to run Elm, which is my goal. – Stan Shunpike Jan 13 '15 at 00:42
  • 1
    The only I know that Sublime can support of Elm is syntax highlighting. – Apanatshka Jan 13 '15 at 07:59
  • Well, that seems consistent with the suggestions I received. So perhaps I just misunderstood what Sublime can be used for. That makes more sense. – Stan Shunpike Jan 13 '15 at 08:21
  • I was recommended to use either Cygwin or Windows Powershell to enter elm commands in. However, so far I've only been able to enter one line of code at a time. How can I enter more than one line of code at once in these interfaces? I want to be able to set up Elm functions but this requires entering more than one line of code at once obviously. I was hoping sublime would be my solution but that doesn't seem like it's the case. I am probably just not understanding how to use Cygwin or Windows Powershell properly so that I can enter several lines of code at once. – Stan Shunpike Jan 13 '15 at 08:40
  • Perhaps you can look for the general solution to setting up Sublime Text 2 to use a command to build? [Here](http://stackoverflow.com/q/10560295/859279)'s a SO question on compiling java, where [this answer](http://stackoverflow.com/a/13488448/859279) seems reusable for Elm. I should repeat I don't know Sublime, but searching the web also got me [this website](http://docs.sublimetext.info/en/latest/reference/build_systems.html) explaining building code. Not sure what version of Sublime Text that documentation is for though. – Apanatshka Jan 13 '15 at 14:50

1 Answers1

2

There should be no need to run Elm through Sublime Text - it's generally pretty simple to run the commands through the Command Prompt.

For development, all you should have to do is:

  1. Install the Windows installer (http://elm-lang.org/Install.elm)
  2. Create a folder for your Elm project (for example in "My Documents")
  3. Open the Command Prompt and cd to this directory - you can do this by typing "cd " (ie just three characters: c, d, and a space) then you can drag the folder with your Elm project into the Command Prompt and press enter (the Command Prompt should now have navigated to this folder)
  4. You can then type elm-reactor in this Command Prompt (this takes the .elm files that it finds in the folder and converts them over to Javascript and Html, and also runs a server that allows you to view the results in the web browser)
  5. Open Sublime Text to this folder to edit the files [*1] (also install Syntax Highlighting by searching Package Control for: "Elm Language Support")
  6. Open your web browser and go to the following address: http://localhost:8000

You should now be able to start developing. In the browser with localhost running, if you click on the wrench icon next to the file with your 'main' function the browser should update automatically when the files are changed (plus you get the time travelling debugger and other good stuff).

[*1] - you could start by jut copying over code from the Examples section of the Elm Lang website, then try modifying these to learn how it works, eg:

import Graphics.Element (..)
import Text (..)

main : Element
main =
  plainText "Hello, World!"

Note:

  • for building the project you can then use elm-make
  • for installing external packages (like elm-html) you you can use elm-package install <package_author>/<package_name> (you can find these in the libraries section of the Elm site)

Hope this helps! Elm's a lot of fun once you get started :)

Chris Berragan
  • 141
  • 1
  • 3
  • This was extremely helpful. I'd like to follow up. So Sublime is just a text editor for Elm. If I am editing code in Sublime, where do I go to run the files? Do I run them from Command Prompt or do I run them from this http://localhost:8000 thing? What is that local host thing? Also, what is the difference between compiling my code and building a project using elm-make? – Stan Shunpike Jan 16 '15 at 04:42
  • I've added a bit more detail to my answer, but to answer your questions directly: "If I am editing code in Sublime, where do I go to run the files?" - you can use a command called "cd" to locate the folder with your elm files in the Command Prompt (eg "cd C:\" will navigate the command prompt to the C drive), "Do I run them from Command Prompt" - yes, once you have navigated to your .elm files in the Command Prompt you can run `elm-reactor` and this will compile the code any time there is a change and let you view it in your browser at the address `http://localhost:8000`. Hope this helps! – Chris Berragan Jan 17 '15 at 09:46