Added some examples that were shown to our handledare.
This commit is contained in:
parent
b0ec5a2333
commit
e2e469d84e
6 changed files with 96 additions and 0 deletions
26
sample-programs/example-programs/ex5.crf
Normal file
26
sample-programs/example-programs/ex5.crf
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
main = case f (Just 10) of {
|
||||
Just a => a ;
|
||||
Nothing => 0 ;
|
||||
};
|
||||
|
||||
f x = bind (fmap (\s . s + 1) x) (\s . pure (s + 10)) ;
|
||||
|
||||
data Maybe () where {
|
||||
Just : Int -> Maybe ()
|
||||
Nothing : Maybe ()
|
||||
};
|
||||
|
||||
fmap : (Int -> Int) -> Maybe () -> Maybe () ;
|
||||
fmap f m = case m of {
|
||||
Just a => pure (f a) ;
|
||||
Nothing => Nothing ;
|
||||
};
|
||||
|
||||
pure : Int -> Maybe () ;
|
||||
pure x = Just x;
|
||||
|
||||
bind : Maybe () -> (Int -> Maybe ()) -> Maybe () ;
|
||||
bind x f = case x of {
|
||||
Just x => f x ;
|
||||
Nothing => Nothing ;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue