[Haskell-beginners] Ambiguous type error: multiparam class + type alias

Sylvain Henry sylvain at haskus.fr
Thu Sep 28 10:58:16 UTC 2017


On 28/09/2017 12:25, Baa wrote:
> Hello, Sylvain.
>
> Your solution assumes that I need to pass `@_ @AsTitle` anywhere where I
> call `repr`? So, instead of `repr n::AsTitle` or `repr n::Something AsTitle`
> (depends on implementation) I'll write `repr @_ @AsTitle n`, right?
Yes.

You could also avoid all this ambiguity/type application stuff with:
data AsTitle = AsTitle
class Repr a b where
   repr :: a -> b -> Repr b
instance Repr Int AsTitle where
   repr n _ = ...
...
print (repr n AsTitle)

(Repr b can be an associated type if you want to support different 
representations)

>
>> You only add a constraint as follows:
>> repr n :: forall b. (Repr b ~ Repr AsTitle, ReprC Int b) => Repr b
> Yes... So, `b` is unbound/free type param. But I can bind it with func.
> deps, yes?
How? If you you bind it with a functional dependency on "a", you can 
only have a single "b" for each "a".

Sylvain


More information about the Beginners mailing list