I’ve always had a fondness for programming languages, and one that caught my eye recently is PureScript – a strongly and statically typed language in the vein of Haskell (which I’ve never really learned proper, though I have it on the ‘maybe someday’ list). PureScript, though, compiles to JavaScript – which, despite it’s warts, is a language that I think is the bees knees.
There’s a book out there for it, available free to read online, so I thought I’d just start going through it to check out the language.
It has you install The Haskell Platform (for the actual compiler), node/npm (for node based utilities and tools), Bower (for all the PureScript packages), and then Grunt (to automate builds and such).
Well, that’s a pretty big stack to install just to write some “Hello World” equivalent programs… but, I don’t mind! Already had most of them installed anyway. However, their setup is not how I prefer to work (when I’m working on my own projects at least).
Here are my deviations from the books setup:
- I installed Bower locally to the folder (I don’t like polluting my global npm packages if I don’t have to… and prefixing
./node_packages/.bin/bower
doesn’t bother me since I’m scripting my builds anyway). - I Started using GNU Make instead of Grunt. Why? Sure, grunt is the new ‘hot’ thing, but, for my purposes, it’s clearly a reinvention of a wheel that works really well. I like GNU Make, and it will serve me better than Grunt (that’s not to say Grunt is useless, but in this instance I prefer to stick with the tried and true).
So, my Makefile
looks something like this:
BOWER_FILES=`find ./bower_components -regex ".*/src/.*\.purs"`
CHAPTER2_FILES=src/Chapter2.purs
PHONEBOOK_FILES=src/Data/PhoneBook.purs
ALL_FILES=${BOWER_FILES} \
${CHAPTER2_FILES} \
${PHONEBOOK_FILES}
all: Chapter2 PhoneBook
bootstrap:
npm install bower
bower install purescript-math#0.1.0
bower install purescript-list
psci:
psci ${ALL_FILES}
Chapter2:
psc ${BOWER_FILES} \
${CHAPTER2_FILES} \
--output dist/Chapter2-Main.js \
--module Chapter2 \
--main Chapter2
Some explanations:
- The definition of
BOWER_FILES
uses backticks around a find command to get a list of all purescript files identified as purescript source files (the community tends to structure their projects a specific way, so this command makes sense for that structure) - The
bootstrap
target can be used to install bower and all the dependancies that are needed for the project - The
psci
target can be used as a shortcut for loading the REPL with all project files - The
Chapter2
a target is for building the file(s) in Chapter 2 – I’ve only read through Chapter 3 so far, and Chapter 2 is the only one that’s had any built files. Chapter 1 was introductory, and Chapter 3 mostly focused on the REPL.
Hopefully I get some time soon to play with PureScript some more! So far my impressions are very positive!