PureScript-Tutorials
Tutorials on using PureScript
Cheat sheet
Initialize new project
pulp --psc-package init
Show instance
newtype Box a = Box a
instance showBox :: (Show a) => Show (Box a) where
show (Box x) = "Box " <> (show x)
Records
Structural record type
type MyRecord = { a :: Int, b :: Number, c :: String }
Nominal record type
newtype MyRecord = MyRecord { a :: Int, b :: Number, c :: String }
Record patterns
f :: forall a. { i :: Int | a } -> { i :: Int }
f { i } = { i: i + 1 }
f :: forall a. { i :: Int | a } -> { i :: Int | a }
f x = x { i = x.i + 1 }
f :: forall a b. a -> b -> { x :: a, y :: b, z :: String }
f = { x: _, y: _, z: "Hello" }
f :: forall a b c. { x :: a | c } -> b -> { x :: b | c }
f = _ { x = _ }
f :: forall a b. { x :: a | b } -> a
f = _.x