Skip to content

PureScript Spickzettel

Stark typisierte funktionale Sprache, die nach JavaScript kompiliert.

01

Erste Schritte

Hello World

PureScript nutzt Haskell-ähnliche Syntax.

purescript
module Main where

import Effect.Console (log)

main = log "Hello, World!"

Funktionen

Typsignaturen verwenden :: und ->.

purescript
add :: Int -> Int -> Int
add a b = a + b

Daten

Algebraische Datentypen mit dem data-Schlüsselwort.

purescript
data Maybe a = Nothing | Just a

data Either a b = Left a | Right b
02

Features

Records

Records mit Row-Polymorphismus.

purescript
type Person = { name :: String, age :: Int }

p :: Person
p = { name: "Alice", age: 30 }

Type Classes

Type Classes für Ad-hoc-Polymorphismus.

purescript
class Show a where
  show :: a -> String

instance showInt :: Show Int where
  show n = showIntImpl n

Do-Notation

Do-Notation für monadischen Code.

purescript
main = do
  log "First"
  log "Second"

Was this helpful?