Fix sample programs
This commit is contained in:
parent
a2f61ea910
commit
a87862a99f
19 changed files with 8 additions and 185 deletions
|
|
@ -1,20 +0,0 @@
|
|||
data Bool () where
|
||||
True : Bool ()
|
||||
False : Bool ()
|
||||
|
||||
not x = case x of
|
||||
True => False
|
||||
False => True
|
||||
|
||||
even : Int -> Bool ()
|
||||
even x = not (odd x)
|
||||
odd x = not (even x)
|
||||
|
||||
main = case even 64 of
|
||||
True => 1
|
||||
False => 0
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
data Bool () where
|
||||
True : Bool ()
|
||||
False : Bool ()
|
||||
|
||||
toBool x = case x of
|
||||
0 => False
|
||||
_ => True
|
||||
|
||||
fromBool b = case b of
|
||||
False => 0
|
||||
True => 1
|
||||
|
||||
main = fromBool (toBool 10)
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
|
||||
|
||||
|
||||
applyId : (forall a. a -> a) -> a -> a
|
||||
applyId f x = f x
|
||||
|
||||
id : a -> a
|
||||
id x = x
|
||||
|
||||
main = applyId id 4
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
add : Int -> Int -> Int ;
|
||||
add x = \y. x+y;
|
||||
|
||||
main : Int ;
|
||||
main = (\z. z+z) ((add 4) 6) ;
|
||||
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
main : Int ;
|
||||
main = (\x. x+x+3) ((\x. x) 2) ;
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
f : Int -> Int ;
|
||||
f x = let g = (\y. y+1) in g (g x)
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
double : Int -> Int ;
|
||||
double n = n + n;
|
||||
|
||||
id : forall a. a -> a ;
|
||||
id x = x ;
|
||||
|
||||
main : Int ;
|
||||
main = id double 5;
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
data Bool () where
|
||||
True : Bool ()
|
||||
False : Bool ()
|
||||
|
||||
-- Both valid
|
||||
-- f : Bool () -> a -> Int
|
||||
f : Bool () -> (forall a. a -> Int)
|
||||
f b = case b of
|
||||
False => (\x. 0 : forall a. a -> Int)
|
||||
True => (\x. 1 : forall a. a -> Int)
|
||||
|
||||
|
||||
main : Int
|
||||
main = (f True) 'h'
|
||||
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
data Bool () where
|
||||
True : Bool ()
|
||||
False : Bool ()
|
||||
|
||||
ifThenElse : Bool () -> a -> a -> a
|
||||
ifThenElse b if else = case b of
|
||||
True => if
|
||||
False => else
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
data Maybe (a) where
|
||||
Nothing : Maybe (a)
|
||||
Just : a -> Maybe (a)
|
||||
|
||||
fromJust : Maybe (a) -> a
|
||||
fromJust a =
|
||||
case a of
|
||||
Just a => a
|
||||
|
||||
fromMaybe : a -> Maybe (a) -> a
|
||||
fromMaybe a b =
|
||||
case b of
|
||||
Just a => a
|
||||
Nothing => a
|
||||
|
||||
maybe : b -> (a -> b) -> Maybe (a) -> b
|
||||
maybe b f ma =
|
||||
case ma of
|
||||
Just a => f a
|
||||
Nothing => b
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
data List (a) where
|
||||
Nil : List (a)
|
||||
Cons : a -> List (a) -> List (a)
|
||||
|
||||
test xs = case xs of
|
||||
Cons Nil _ => 0
|
||||
|
||||
List a /= List (List a)
|
||||
|
||||
a /= List a
|
||||
|
|
@ -1 +0,0 @@
|
|||
main = 5 + 2;
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
main = case 78 of {
|
||||
5 => 45;
|
||||
x => x + 24;
|
||||
};
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
data Maybe () where {
|
||||
Just : Int -> Maybe () ;
|
||||
Nothing : Maybe () ;
|
||||
};
|
||||
|
||||
demoFunc x = case x of {
|
||||
Just y => y + 24;
|
||||
Nothing => 0;
|
||||
};
|
||||
|
||||
main = demoFunc (Just 5) ;
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
data Maybe () where
|
||||
Just : Int -> Maybe ()
|
||||
Nothing : Maybe ()
|
||||
|
||||
demoFunc x = case x of
|
||||
Just x => x + 24
|
||||
Nothing => 0
|
||||
|
||||
main = demoFunc Nothing
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
main = sum (repeat (sumlength (repeat 10 2000)) 5);
|
||||
|
||||
-- a simple list data type containing ints
|
||||
data List () where {
|
||||
Cons : Int -> List () -> List ()
|
||||
Nil : List ()
|
||||
};
|
||||
|
||||
-- take the length of a list
|
||||
length : List () -> Int ;
|
||||
length x = case x of {
|
||||
Cons _ xs => 1 + length xs ;
|
||||
Nil => 0 ;
|
||||
};
|
||||
-- sum a list
|
||||
sum : List () -> Int ;
|
||||
sum x = case x of {
|
||||
Cons a xs => a + sum xs ;
|
||||
Nil => 0 ;
|
||||
};
|
||||
|
||||
-- sum + length of a list
|
||||
sumlength: List () -> Int ;
|
||||
sumlength x = sum x + length x ;
|
||||
|
||||
-- take the head of a list
|
||||
head : List () -> Int ;
|
||||
head x = case x of {
|
||||
Cons h _ => h ;
|
||||
};
|
||||
|
||||
-- repeat an element n times
|
||||
repeat : Int -> Int -> List () ;
|
||||
repeat x n = repeatHelp Nil x n;
|
||||
repeatHelp : List () -> Int -> Int -> List () ;
|
||||
repeatHelp acc x n = case n of {
|
||||
0 => acc ;
|
||||
n => repeatHelp (Cons x acc) x (n + minusOne) ;
|
||||
};
|
||||
|
||||
-- represents minus one :)
|
||||
minusOne : Int ;
|
||||
minusOne = 9223372036854775807 + 9223372036854775807 + 1;
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
const2 : a -> b -> a
|
||||
const2 x y = x
|
||||
|
||||
f : a -> a
|
||||
f x = (const2 x 'c')
|
||||
|
||||
main = f 5
|
||||
|
|
|
|||
|
|
@ -1,13 +1,16 @@
|
|||
data Either(a b) where
|
||||
Left: a -> Either (a b)
|
||||
Right: b -> Either (a b)
|
||||
data Either (a b) where
|
||||
Left : a -> Either (a b)
|
||||
Right : b -> Either (a b)
|
||||
|
||||
unwrapLeft : Either (a b) -> a
|
||||
unwrapLeft x = case x of
|
||||
Left y => y
|
||||
|
||||
unwrapRight : Either (a b) -> b
|
||||
unwrapRight x = case x of
|
||||
Right y => y
|
||||
|
||||
wow : Either (Int Char)
|
||||
wow = Left 5
|
||||
|
||||
main = unwrapLeft wow
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue