Reputation: 63
I have this Haskell function i'm trying to convert into Scala.
In Haskell you have a function like:
trifecta :: (a->b) -> (b->c) -> (c->d) -> a -> d
I haven't found anything online about converting these kinds of type signature in Scala.
This is what I have done so far, but I'm not quite sure this is correct.
Scala Code:
def trifecta[A,B,C,D](a: (A=>B), b: (B=>C), c: (C=>D), d: A): D = {
trifecta(a, b, c, d)
}
I'd really appreciate if you guys could help me clarify this. Thank You!
Upvotes: 3
Views: 191
Reputation: 144206
Your types are fine but your implementation won't terminate. You probably meant:
def trifecta[A,B,C,D](a: A=>B, b: B=>C, c: C=>D, d: A): D = c(b(a(d)))
if you want it to be curried like the Haskell version you need separate argument lists:
def trifecta[A,B,C,D](a: A=>B)(b: B=>C)(c: C=>D)(d: A): D = c(b(a(d)))
Upvotes: 6