[Haskell-cafe] What is this applicative functor?
oleg.grenrus at iki.fi
Wed Feb 1 07:34:10 UTC 2017
These instances are quite similar to
(I wish `disorder-jack` were already on Hackage!)
On 01.02.2017 07:28, David Menendez wrote:
> On Tue, Jan 31, 2017 at 11:55 PM, Joachim Breitner
> <mail at joachim-breitner.de <mailto:mail at joachim-breitner.de>> wrote:
> Am Dienstag, den 31.01.2017, 15:22 -0500 schrieb Joachim Breitner:
> > 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?
> I guess it does not exist, so I am preparing a package for it here:
> The source code contains (in comments) a proof of the Applicative
> My gut feeling says that this does not have a Monad instance that is
> compatible with the given Applicative instance, but it is too late
> today to substantiate this feeling. If anyone feels like puzzling: Can
> you come up with a Monad instance, or (more likely) give good reasons
> why there cannot be one?
> How about this?
> hd (OneStep x xs) = x
> instance Monad OneStep where
> OneStep x xs >>= f = OneStep y (map (hd . f) xs ++ ys)
> OneStep y ys = f x
> Not sure if it’s good for anything, but it seems valid and consistent
> based on a preliminary investigation.
> Dave Menendez <dave at zednenem.com <mailto:dave at zednenem.com>>
> <http://www.eyrie.org/~zednenem/ <http://www.eyrie.org/%7Ezednenem/>>
> 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 819 bytes
Desc: OpenPGP digital signature
More information about the Haskell-Cafe