[Haskell-cafe] Deepest polymorphic functor

Ryan Ingram ryani.spam at gmail.com
Thu Jul 30 23:25:05 EDT 2009


The problem is this:

> instance Num a => Num [a] where ...
>
> test = deep_fmap (+1) [[[ 1, 2, 3 :: Int ]]]

What (+1) should be used?

(+1) :: Int -> Int
(+1) :: [Int] -> [Int]
(+1) :: [[Int]] -> [[Int]]
(+1) :: [[[Int]]] -> [[[Int]]]

They could all be type-correct, so the snippet is ambiguous.
Monotypes are required to avoid the ambiguity.

As to why you might want an instance of this form, they are very nice
for representing (possibly infinite) power series[1] of the form
c0 + c1 * x + c2 * x^2 + c3 * x^3 + ...

As to your other question, in my experience it seems that yes, type
equality constraints can replace the awkward "TypeCast" classes of
oleg-ery.

  -- ryan

[1] Mcilroy: Functional Pearl: Power Series, Power Serious.
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.38.9450
Code here: http://journals.cambridge.org/fulltext_content/supplementary/JFP/online/jfpvol9-3/power-pearl/appendix.hs


More information about the Haskell-Cafe mailing list