[Haskell-beginners] type classes and multiple implementations

Sean Bartell wingedtachikoma at gmail.com
Fri Jun 5 13:09:11 EDT 2009


    by_type :: Storage a => String -> String -> IO a
This function must, for any Storage type, take any two strings and produce
an IO value of that type. (by_type "disk" "xyz" :: Memory must be valid.) It
doesn't really have the option of choosing which instance of Storage to use.

In pure Haskell, you would probably have to do something like
  type Storage = Disk Handle | Memory String
  by_type :: String -> String -> Storage
That way, by_type can return any Storage it wants.

I'm sure there are also ways to do what you want with extensions.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090605/be33076a/attachment.html


More information about the Beginners mailing list