[Haskell-cafe] Re: Rewrite class with fundeps in pure h98?
apfelmus
apfelmus at quantentunnel.de
Tue Jun 3 13:17:45 EDT 2008
Darrin Thompson wrote:
> I thought that I should be able to write something like the toHtml
> function below with pure H98, but when I went to write it I ended up
> needing fundeps. Is there a way to express this without using any
> extensions?
>
> The idea was to take a remotely Dom-like tree and flatten it into a
> string, but not require any particular string type.
>
> data (IsString s, Monoid s) => Dom s =
> Element s [Attr s] [Dom s] |
> Text s
>
> data (IsString s, Monoid s) => Attr s = Attr s s
>
> class (Monoid s, IsString s) => HTML d s | d -> s where
> toHtml :: d -> s
>
> instance (Monoid s, IsString s) => HTML (Dom s) s where
>
> instance (Monoid s, IsString s) => HTML (Attr s) s where
The H98 way is to make a class for type constructors:
class HTML d where
toHTML :: (Monoid s, IsString s) => d s -> s
instance HTML Dom where ...
instance HTML Attr where ...
Btw, naming the class "HTML" is feels wrong, something like Serialize is
probably a better fit.
Regards,
apfelmus
More information about the Haskell-Cafe
mailing list