Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # No compila, por que?
- alias AbBool = Nil |
- Bool |
- Tuple(AbBool, AbBool)
- def fold(e : AbBool, fNil : -> T, fBool : Bool -> T, fTup : Proc(T, T, T))
- case e
- when Nil
- fNil.call()
- when Bool
- fBool.call(e)
- when Tuple(AbBool, AbBool)
- rec1 = fold(e.fst, fNil, fBool, fTup)
- rec2 = fold(e.snd, fNil, fBool, fTup)
- fTup.call(rec1, rec2)
- end
- end
- struct Tuple
- def fst
- self[0].not_nil!
- end
- def snd
- self[1].not_nil!
- end
- end
- 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