[Haskell-cafe] Call for discussion: OverloadedLists extension

Heinrich Apfelmus apfelmus at quantentunnel.de
Tue Sep 25 18:21:24 CEST 2012

Michael Snoyman wrote:
> Note that I wasn't necessarily advocating such a pragma. And a lot of
> my XML code actually *does* use two IsString instances at the same
> time, e.g.:
>     Element ("img" :: Name) (singleton ("href" :: Name) ("foo.png" ::
> Text)) [NodeComment ("No content inside an image" :: Text)]

In this particular case, would it make sense to use smart constructors 

The idea is that you can put the polymorphism in two places: either make 
the "output" polymorphic, or make the "input" polymorphic. The latter 
would correspond to a type

    element :: (IsString name, IsString s, IsMap map)
        => name -> map name s -> [Element]
    element name map = Element (toName name) (toMap map)

One benefit would be that the function will accept any list as a map, 
not just list literals.

Best regards,
Heinrich Apfelmus


More information about the Haskell-Cafe mailing list