I am trying to find a way to do something like this:
(head, last) `someFunction` [1, 2, 3]
to get a tuple (1, 3)
as an output.
Apparently, in theory, it looks like an applicative functor, but a little back. I suppose there is a similar function that does this (or some way of creating it), but I cannot find / understand it.
I tried to define a function like this:
fmap' :: ((a -> b), (a -> b)) -> [a] -> (b, b) fmap' (f1, f2) xs = (f1 xs, f2 xs)
but the GHC does not actually compile this.
Any help would be great; thanks!
Edit (whole year!):
My fmap'
will not compile because the type signature was incorrect. Obviously there are better ways to do what I am doing, but my fmap'
type should be as follows:
fmap' :: ((a -> b), (a -> b)) -> a -> (b, b)
In this case, it compiles and works just fine.