Skip to content

Instantly share code, notes, and snippets.

@maddie927
Last active January 4, 2020 06:40
Show Gist options
  • Save maddie927/a2e712bc1872ee9eb898 to your computer and use it in GitHub Desktop.
Save maddie927/a2e712bc1872ee9eb898 to your computer and use it in GitHub Desktop.
What is it?
  • compiles to js
  • haskell-inspired type system (with some improvements!)
  • no runtime (unlike elm, ghcjs, etc)
  • focus on readable and debuggable js

Installing

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

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
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment