-
Notifications
You must be signed in to change notification settings - Fork 9
Haskell
ptol edited this page Mar 20, 2017
·
4 revisions
foo :: Int -> Int
foo 1 = 2
foo 2 = 3
map (\x -> x + 1) list
|
foo : Int => Int
foo = case
1 => 2
2 => 3
map (x => x + 1) list -- \ is optional |
foo = 2
case x of
1 -> 2
x | x == foo -> 3 |
foo = 2
x # case -- (#) == (&)
1 => 2
^foo => 3 -- pattern with external variable |
data FooBar = Point {
foo :: Int,
bar :: String
}
p = Point {foo = 1, bar = "bar"}
p2 = p {foo = 2}
valFoo = foo p |
type FooBar =
foo : Int
bar : String
p = (foo = 1, bar = "bar")
p2 = p with foo = 2
valFoo = p.foo |
Tuple is a record with itemN labels
foo = (1, 2) |
foo = (1, 2) -- same as foo = (item1 = 1, item2 = 2) |
The name of the module is defined by file path
module Oczor.Bar where
foo = 1
import Oczor.Bar
bar = foo
|
oczor/bar.oc
foo = 1
import oczor.bar
bar = foo |
Oczor uses records instead of Type Constructors
data Maybe a = Nothing | Just a
maybe :: b -> (a -> b) -> Maybe a -> b
maybe n _ Nothing = n
maybe _ f (Just x) = f x
|
type Maybe a = none | just : a -- none is a constant with type None
maybe : b, (a => b), Maybe a => b
maybe = case
n _ ^none => n
_ f (just = x) => f x |
class Show a where
show :: a -> String
instance Show Int where
show x = "Int" |
class show a : a => String
instance Int show x = "Int"
|