[Haskell-cafe] Re: Type-level programming problem

Thomas Schilling nominolo at googlemail.com
Tue May 1 15:19:27 EDT 2007


On 1 maj 2007, at 06.12, oleg at pobox.com wrote:
>
> We see it is a value polymorphic over four type variables: ns, a, b,
> and c. The type variable 'a' is also the type of the value, so we have
> a way to instantiate it. There is no direct way to instantiate the
> remaining three. If there were a functional dependency a -> ns, a->b,
> a->c, we could have instantiated the remaining variables. But there
> are no such dependencies. So, there is really no way we can
> ever instantiate the type variables ns, b and c -- and so the  
> typechecker
> will complain.
>
> So, we need either a functional dependency a -> ns in the definition
> of Foo, or defaultA should have a signature defaultA :: ns -> a
> (and ditto for other defaults).

In fact I had this signature for a while, but then I had already  
changed the definition of Foo to a different signature.  Good to know  
that I wasn't too far off..

> As I understand, the function
> 'defaultA' can be present in different components, identified by
> ns. When we write 'defaultA' however, how can we say that we mean
> defaultA of component X rather than of component Y? There isn't any
> way to name the desired component...
>
> Incidentally, if we represent components by records
> 	data XRec = XRec { defaultA :: XA }
> then the type of defaultA is Xref -> XA. It is the function from the
> type of the `namespace'. This seems to suggest the
> signature of defaultA should be ns -> a ...
>
> BTW, there are other ways to add the name of the namespace to the
> signature of defaultA. For example:
> 	newtype TaggedT ns a = TaggedT a
> 	class Foo ns a b c | ...
> 	 defaultA :: TaggedT ns a
> or
> 	class Foo ns a b c | ...
> 	 defaultA :: ns a
>
> etc.

Thank you for your quick and helpful response.  I'll look into what  
works best for my purposes.

Thanks,

/ Thomas



More information about the Haskell-Cafe mailing list