I'm trying to do find a way to do something like this:
(head, last) `someFunction` [1, 2, 3]
to produce the tuple (1, 3)
as output.
It seems similar in theory to an applicative functor, but a little backwards. I'm guessing there's a similar function that does this (or some way to make one), but I can't seem to find it/figure it out.
I tried defining a function like this:
fmap' :: ((a -> b), (a -> b)) -> [a] -> (b, b)
fmap' (f1, f2) xs = (f1 xs, f2 xs)
but GHC won't actually compile this.
Any help would be great; thanks!
Edit (a whole year later!):
My fmap'
wouldn't compile because the type signature was wrong. Obviously there are better ways to do what I was doing, but the type of my fmap'
should instead be:
fmap' :: ((a -> b), (a -> b)) -> a -> (b, b)
In that case, it compiles and runs just fine.