Guest User

Untitled

a guest
Aug 10th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. type Stack =
  2. | Empty
  3. | Stack of String list
  4.  
  5. let push item deck =
  6. match deck with
  7. | Empty -> Stack [item]
  8. | Stack d -> Stack (item::d)
  9.  
  10. let pop (Stack d) =
  11. match d with
  12. | h::[] -> h,Empty
  13. | h::t -> h,(Stack t)
  14.  
  15. let empty = Empty
  16. let s,st = pop empty
  17.  
  18. let pop stack =
  19. match stack with
  20. | Empty -> None, Empty
  21. | Stack (h::[]) -> Some h,Empty
  22. | Stack (h::t) -> Some h,(Stack t)
  23.  
  24. let pop stack =
  25. match stack with
  26. | Empty -> Error "Empty Stack"
  27. | Stack (h::[]) -> Ok (h,Empty)
  28. | Stack (h::t) -> Ok (h,(Stack t))
Add Comment
Please, Sign In to add comment