Skip to content

Instantly share code, notes, and snippets.

@megamaddu
Last active January 4, 2020 06:40
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save megamaddu/a2e712bc1872ee9eb898 to your computer and use it in GitHub Desktop.
Save megamaddu/a2e712bc1872ee9eb898 to your computer and use it in GitHub Desktop.
What is it?
  • Compiles to JavaScript
  • Haskell-inspired type system (with some improvements!)
  • No runtime (unlike Elm, GHCJS, etc)
  • A focus on readable and debuggable JavaScript

Installing

npm i -g purescript pulp
PureScript
  • psc
  • psci
  • ...
Pulp
  • pulp init
  • pulp build
  • pulp test
  • pulp docs
  • pulp server

Editor Support

Atom via psc-ide, ide-purescript, and language-purescript

git clone https://github.com/kRITZCREEK/psc-ide.git
cd psc-ide
stack install
apm install ide-purescript purescript-language

Vim and Emacs plugins too!

Let's compile some code!

x :: Number
x = 5.0
y :: Int
y = 5
import Prelude ((+))

add :: Number -> Number -> Number
add x y = x + y
import Prelude ((+))

add :: Int -> Int -> Int
add x y = x + y
data Maybe a = Nothing | Maybe a
data Maybe a = Nothing | Maybe a

greeting :: Maybe String
greeting = Just "hello."

silence :: Maybe String
silence = Nothing
type User = { name :: String
            , email :: String
            }

type Userish a = { name :: String
                 , email :: String
                 | a
                 }
import Prelude
import Control.Monad.Eff
import Control.Monad.Eff.Console

sayHi :: forall eff. Eff (console :: CONSOLE | eff) Unit
sayHi = log "hello world."

main = sayHi
data Direction
  = North
  | South
  | East
  | West

class Reversible a where
  reverse :: a -> a

instance reversibleDirection :: Reversible Direction where
  reverse North = South
  reverse South = North
  reverse East = West
  reverse West = East

mirror :: forall a. (Reversible a) => a -> Tuple a a
mirror a = Tuple a (reverse a)

Project!

Completed Main.purs (don't cheat!)

More stuff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment