Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. # No compila, por que?
  2. alias AbBool = Nil |
  3. Bool |
  4. Tuple(AbBool, AbBool)
  5.  
  6. def fold(e : AbBool, fNil : -> T, fBool : Bool -> T, fTup : Proc(T, T, T))
  7. case e
  8. when Nil
  9. fNil.call()
  10. when Bool
  11. fBool.call(e)
  12. when Tuple(AbBool, AbBool)
  13. rec1 = fold(e.fst, fNil, fBool, fTup)
  14. rec2 = fold(e.snd, fNil, fBool, fTup)
  15. fTup.call(rec1, rec2)
  16. end
  17. end
  18.  
  19. struct Tuple
  20. def fst
  21. self[0].not_nil!
  22. end
  23.  
  24. def snd
  25. self[1].not_nil!
  26. end
  27. end
  28.  
  29. puts fold( {nil, {true, false}}, ->{0}, ->(b : Bool){b ? 1 : 0}, ->(reci : Int32, recd : Int32){reci + recd } )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement