[Haskell-cafe] Functional dependencies and overloading of operation

adam vogt vogt.adam at gmail.com
Mon Feb 29 20:36:28 UTC 2016

On Sun, Feb 28, 2016 at 4:00 PM, Kristoffer Føllesdal <kfollesdal at gmail.com>

> What I want is to have the «same» function for these cases:
> operation :: a -> a -> Vect k a
> operation :: a -> Vect k a -> Vect k a
> operation :: Vect k a -> a -> Vect k a
> operation :: Vect k a -> Vect k a -> Vect k a

You might be able to write it in terms of a function that can take either
of these signatures

ensureVect :: a -> Vect k a
ensureVect :: Vect k a -> Vect k a

-- then you can write
operation x y = ensureVect x `opA` ensureVect y

I have something close to that here <
https://gist.github.com/aavogt/3b295008fbcde2ea88dd>, except it uses Maybe.
The example wouldn't work with (+) and numeric literals [there could be an
instance Num a => Num (Maybe a), after all], and I think it's likely that
the code you want to write will run into the same problem.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160229/6d318604/attachment.html>

More information about the Haskell-Cafe mailing list