Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Html exposing (Html, text)
- type Option a = None | Some a
- (>>=) : Option a -> (a -> Option b) -> Option b
- (>>=) m f =
- case m of
- None ->
- None
- Some x ->
- f x
- return : a -> Option a
- return x = Some x
- div : Int -> Int -> Option Int
- div x y =
- if y == 0
- then None
- else Some (x // y)
- test : Int -> Int -> Int -> Option Int
- test x y z =
- div x y >>= \t ->
- div t z >>= \t ->
- return t
- show : Option a -> Html b
- show m =
- case m of
- None -> text "None"
- Some x -> text ("Some " ++ (toString x))
- main = test 3 0 1 |> show
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement