5 ms·
If the type of C is a type D -> E -> F... then you're already there. Or I'm misunderstanding the question. (In which case, please, somebody correct me.) But i
by eckza 4y ago
If the type of C is a type D -> E -> F... then you're already there.
Or I'm misunderstanding the question. (In which case, please, somebody correct me.)
But if I'm not... Elm, Haskell, F#, and probably most other FP langs support this.
- bhaney 4y agoSorry, I just realized that the pseudo-notation I was using to represent a partial type signature is similar to the actual type signature notation that Haskell and Elm use, so that's probably confusing things. What I specifically meant by "(A -> B, B -> C)" was "two arguments, each of which are unary functions, and the type of the argument accepted by the second function is the same as the the return type of the first function." I think in formal notation, the full signature would be "(a -> b) -> (b -> c) -> (a -> c)" but I'm not overly familiar with that notation so I may have gotten that wrong. The goal here is to be able to describe a function as mentioned in the article, that can accept any number of functions (either as varargs or a single list of functions), and ensure that the input of each provided function has the same type as the output of the function that precedes it.
- consilient 4y agoHaskell can do this, although it's pretty unidiomatic: data AlignedFunctionList a b where Identity :: AlignedFunctionList x x Pipe :: (x -> y) -> AlignedFunctionList y z -> AlignedFunctionList x z pipe :: AlignedFunctionList a b -> (a -> b) pipe Identity a = a pipe (Pipe f g) a = pipe g (f a)
- yakshaving_jgt 4y agoI must be missing something, but in Haskell this “typed pipe” (which is just reverse application) already exists in the base package as Data.Function.&. (&) :: a -> (a -> b) -> b
- siknad 4y ago> that can accept any number of functions So, `(a -> b) -> (b -> c) -> (c -> d) -> ... -> a -> z`.
- yakshaving_jgt 4y agoAh, right. In that case I suppose you'd want some kind of fold.