Improving void

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Tue Aug 6 09:04:11 CEST 2013


On 6 August 2013 16:32, Malcolm Wallace <malcolm.wallace at me.com> wrote:
> Can you explain why you think it is an improvement?
> To me, it looks like line noise.

I think it's becaue (<$) is a method of the Functor class, with a
default definition of "fmap . const"; however, it's possible that some
instances might have a custom definition which would be more efficient
than using "fmap (const ())".

>
>  Regards,
>     Malcolm
>
> On 5/08/2013, at 20:06, Edward Kmett <ekmett at gmail.com> wrote:
>
> Right now the definition of Control.Monad.void is:
>
> void :: Functor f => f a -> f ()
>
> void = fmap (const ())
>
> I propose we replace it with
>
> void :: Functor f => f a -> f ()
>
> void = (() <$)
>
> This expands out to the former definition by the default definition of (<$)
> and Data.Functor.Functor exports (<$) explicitly to make it possible to
> optimize this sort of thing. It seems a shame not to use it.
>
> Discussion Period: 2 weeks
>
> _______________________________________________
>
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>



-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
http://IvanMiljenovic.wordpress.com




More information about the Libraries mailing list