Merge remote-tracking branch 'origin/typechecking-merge' into pattern-matching-with-typechecking

This commit is contained in:
Samuel Hammersberg 2023-03-23 16:33:05 +01:00
commit d3d173eb59
21 changed files with 1052 additions and 476 deletions

View file

@ -1,29 +1,8 @@
posMul : _Int -> _Int -> _Int;
posMul a b = a + b; {-case b of {
0 => 0;
_ => a + posMul a (b - 1)
};-}
main : _Int;
main = posMul 5 10;
--
-- facc : _Int -> _Int;
-- facc a = case a of {
-- 1 => 1;
-- _ => posMul a (facc (a - 1))
-- };
--
-- minimization : (_Int -> _Int) -> _Int -> _Int;
-- minimization p x = case p x of {
-- 1 => x;
-- _ => minimization p (x + 1)
-- };
--
-- checkFac : _Int -> _Int;
-- checkFac x = case facc x of {
-- 0 => 1;
-- _ => 0
-- };
--
-- main : _Int;
-- main = minimization checkFac 1
posMul: _Int - > _Int - > _Int;
posMul a b = a + b; {
-
case b of {
0 => 0;
_ => a + posMul a(b - 1)
}; -
}

5
sample-programs/basic-2 Normal file
View file

@ -0,0 +1,5 @@
add : Int -> Int -> Int ;
add x = \y. x+y;
main : Int ;
main = (\z. z+z) ((add 4) 6) ;

2
sample-programs/basic-3 Normal file
View file

@ -0,0 +1,2 @@
main : Int ;
main = (\x. x+x+3) ((\x. x) 2) ;

2
sample-programs/basic-4 Normal file
View file

@ -0,0 +1,2 @@
f : Int -> Int ;
f x = let g = (\y. y+1) in g (g x)

8
sample-programs/basic-5 Normal file
View file

@ -0,0 +1,8 @@
double : Int -> Int ;
double n = n + n;
id : forall a. a -> a ;
id x = x ;
main : Int ;
main = id double 5;

10
sample-programs/basic-6 Normal file
View file

@ -0,0 +1,10 @@
data Bool () where {
True : Bool ()
False : Bool ()
};
main : Bool () -> Int ;
main b = case b of {
False => 0;
True => 0
}

10
sample-programs/basic-7 Normal file
View file

@ -0,0 +1,10 @@
data Bool () where {
True : Bool ()
False : Bool ()
};
ifThenElse : forall a. Bool () -> a -> a -> a;
ifThenElse b if else = case b of {
True => if;
False => else
}

24
sample-programs/basic-8 Normal file
View file

@ -0,0 +1,24 @@
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
}