
Together with Sebastiaan Visser, I've been working on a library called AwesomePrelude [1]. This is a library where we try to reimplement the Prelude by replacing all concrete data types with type classes. This way you can have multiple implementations of a "data type". This is our current implementation of a list:
class ListC j where nil :: j [a] cons :: j a -> j [a] -> j [a] list :: j r -> (j a -> j [a] -> j r) -> j [a] -> j r
The two constructors (Nil, Cons) have been replaced by two equivalent methods (nil, cons), and the concept of pattern matching for this data type has been replaced by a single method (list). A couple of weeks ago, we presented [2] the current version of the library. Where we have JavaScript instances for the different type classes. E.g:
xs ++ ys
Represents a JavaScript AST that concatenates two JavaScript lists.
And finally, would having only type classes make the type system any simpler?
In our library, the types definitely don't get simpler, but thats
probably because it also still deals with concrete JavaScript data
types.
- Tom Lokhorst
[1]: http://github.com/tomlokhorst/AwesomePrelude
[2]: http://tom.lokhorst.eu/2010/02/awesomeprelude-presentation-video
On Fri, Feb 26, 2010 at 1:35 PM, Pasqualino "Titto" Assini
Hi, just a silly question (or maybe more than one):
In Haskell we have data types (Integer,[a],...) as well as type classes (Num, Ord...).
But, if we have type classes do we still need types?
Why shouldn't the objects that we process be defined only by their 'interfaces' (assuming that a type class is a kind of interface)?
Maybe the real question is: are type classes a more primitive concept than data types?
And if so, in a language that had only type classes what would a data declaration like the following map to:
data List a = Cons a (List a) | Nil
And what about pattern matching? Would that still be possible, and what form would it take?
And finally, would having only type classes make the type system any simpler?
Thanks,
titto _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe