[Haskell-cafe] What is this applicative functor?
cma at bitemyapp.com
Tue Jan 31 20:24:31 UTC 2017
On Tue, Jan 31, 2017 at 2:22 PM, Joachim Breitner
<mail at joachim-breitner.de> wrote:
> I recently wrote this applicative functor:
> data OneStep a = OneStep a [a]
> instance Functor OneStep where
> fmap f (OneStep o s) = OneStep (f o) (map f s)
> instance Applicative OneStep where
> pure x = OneStep x 
> OneStep f fs <*> OneStep x xs = OneStep (f x) (map ($x) fs ++ map f xs)
> takeOneStep :: OneStep t -> [t]
> takeOneStep (OneStep _ xs) = xs
> This was useful in the context of writing a shrink for QuickCheck, as
> discussed at http://stackoverflow.com/a/41944525/946226.
> Now I wonder: Does this functor have a proper name? Does it already
> exist in the libraries somewhere? Should it?
> Joachim “nomeata” Breitner
> mail at joachim-breitner.de • https://www.joachim-breitner.de/
> XMPP: nomeata at joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F
> Debian Developer: nomeata at debian.org
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> Only members subscribed via the mailman list are allowed to post.
Currently working on http://haskellbook.com
More information about the Haskell-Cafe