Skip to content

Instantly share code, notes, and snippets.

@alexnask
Created May 3, 2012 23:52
Show Gist options
  • Select an option

  • Save alexnask/2590520 to your computer and use it in GitHub Desktop.

Select an option

Save alexnask/2590520 to your computer and use it in GitHub Desktop.
Attempt to create a function composition operator in ooc
// 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)
// 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