Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.61 KB | None | 0 0
  1. import Html exposing (Html, text)
  2.  
  3.  
  4. type Option a = None | Some a
  5.  
  6.  
  7. (>>=) : Option a -> (a -> Option b) -> Option b
  8. (>>=) m f =
  9.   case m of
  10.     None ->
  11.       None
  12.      
  13.     Some x ->
  14.       f x
  15.  
  16.  
  17. return : a -> Option a
  18. return x = Some x
  19.  
  20.  
  21. div : Int -> Int -> Option Int
  22. div x y =
  23.   if y == 0
  24.   then None
  25.   else Some (x // y)
  26.  
  27.  
  28. test : Int -> Int -> Int -> Option Int
  29. test x y z =
  30.   div x y >>= \t ->
  31.   div t z >>= \t ->
  32.     return t
  33.  
  34.  
  35. show : Option a -> Html b
  36. show m =
  37.   case m of
  38.     None -> text "None"
  39.     Some x -> text ("Some " ++ (toString x))
  40.  
  41.  
  42. main = test 3 0 1 |> show
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement