Skip to content

Haskell

ptol edited this page Sep 20, 2016 · 4 revisions

Some differences from Haskell

Functions

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

Case

foo = 2
case x of
  1 -> 2
  x | x == foo -> 3
foo = 2
x # case -- (#) == (&)
  1 => 2
  ^foo => 3 -- pattern with external variable

Records

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

Tuples

Tuple is a record with itemN labels

foo = (1, 2)
foo = (1, 2) -- same as foo = (item1 = 1, item2 = 2)

Modules

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

Types

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

Classes

class Show a where
  show :: a -> String
instance Show Int where
show x = "Int"
class show a : a => String
instance Int show x = "Int"
Clone this wiki locally