[Haskell-cafe] Traversable instance for ((->) a)?

Michael Sloan mgsloan at gmail.com
Wed Sep 20 21:18:44 UTC 2017


It isn't, in ghci try ":m + Data.Traversable" and ":info (->)".  It
should be possible to define an "instance Bounded a, Enum a, Eq a) =>
Traversable ((->) a)", it would only work on total functions with
finitely enumerable inputs.  It would be exactly like "Ord a =>
Traversable (Map a)", except it also needs to convert the function
into this map representation by enumerating all inputs. With just the
Eq constraint, the resulting function would be very inefficient as it
would need to scan all (input, output) pairs to find the matching one.
So you'd probably want an Ord or Hashable constraint and use Map or
HashMap.

Since this process is so slow, it doesn't make much sense to have this
instance defined, it is not a very normal thing to do with functions.
More likely to cause confusing type errors when the user intended to
use traverse with some other type.

-Michael

On Wed, Sep 20, 2017 at 10:33 AM, David Banas <capn.freako at gmail.com> wrote:
> Is there a Traversable instance for ((->) a)?
> -db
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.


More information about the Haskell-Cafe mailing list