[Haskell-cafe] Re: Type hackery help needed!

oleg at pobox.com oleg at pobox.com
Sat Aug 5 05:43:30 EDT 2006


> A value of any type should be embeddable inside a build expression
> of any result type, i.e. a -> b or b -> a cannot hold on Embed in
> general.

It seems you might benefit from local functional dependencies, which
are asserted per instance rather than for the whole class. They are
explained in

	http://pobox.com/~oleg/ftp/Haskell/typecast.html 

Incidentally, that web page's source also gives an illustration of their
use:
	http://pobox.com/~oleg/ftp/Haskell/typecast.hs

The page itself is written in HSXML, which had to deal with a similar
problem: in HSXML, 'p' is a polyvariadic function, which has to accept
as many strings as the user cares to specify -- and in addition,
arbitrary HSXML fragments like 'em', 'code', 'cite', etc. The latter
are too built by polyvariadic functions. So, at some point I had to
force the constraints and tell the functions that their arguments are
over and they better give some data structure. Incidentally, that's
where [] notation comes in quite handy. The brackets are not just the
embellishment; by lucky accident, they actually force the
constraints. BTW, the rendering of the above HSXML code checks local
file links (and inserts the file sizes into the HTML code, while at
it). There is a version of the HSXML rendering that, in addition to
formatting Haskell code, passes it to a Haskell system to verify its
typing -- and to optionally run it as well. The complete source code
for the renderers is
	http://pobox.com/~oleg/ftp/Haskell/HSXML.tar.gz



More information about the Haskell-Cafe mailing list