Created
May 3, 2012 23:52
-
-
Save alexnask/2590520 to your computer and use it in GitHub Desktop.
Attempt to create a function composition operator in ooc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This does not work, rock moans that there is not enough info to resolve return type T of function call... BS if you ask me :P | |
| operator => <T,K,V> (l: Func(V)->T, r: Func(K)->V)-> Func(K)->T { | |
| func(arg: K) -> T { | |
| l(r(arg)) | |
| } | |
| } | |
| // Haskell: f = g . h | |
| // Equivalent to f x = g (h x) | |
| // ooc: f := g => h | |
| // Equivalent to f := func <T,K> (arg: T) -> K { g(h(arg)) } | |
| f := String println => SSizeT toString | |
| f(42) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // We compromise and only make compositions that return nothing... This passes ooc compilation but fails at C compilation :-( | |
| operator => <K,V> (l: Func(V), r: Func(K)->V)-> Func(K) { | |
| func(arg: K) { | |
| l(r(arg)) | |
| } | |
| } | |
| // Haskell: f = g . h | |
| // Equivalent to f x = g (h x) | |
| // ooc: f := g => h | |
| // Equivalent to f := func <T,K> (arg: T) -> K { g(h(arg)) } | |
| f := String println => SSizeT toString | |
| (f as Func(SSizeT))(42) // Also note the cast, you need to cast every generic type in ooc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment