Hacker News new | ask | show | jobs
by prepor 3505 days ago
You can do everything that you can with typeclasses without them. In fact GHC compiles Haskell into GHC core, where are no typeclasses.

See http://okmij.org/ftp/Computation/typeclass.html

3 comments

Quote from the second paragraph:

> Knowing what TEDIOUS JOB GHC is doing for us helps us appreciate more the convenience of type classes.

Thanks for the link though, I think I read it a few years ago.

In truth, it's a balancing act. More than a few Haskell libraries are more tedious than Elm code (I've written upwards of 8,000 lines of production Elm but have been doing Haskell for much longer) because they're so intensely abstract.

Without typeclasses, that simply doesn't happen. I'd say 90% or more of Haskell typeclass usage is pointless, and maybe half of what remains is simple to replace with simpler polymorphism or no polymorphism.

For instance, almost everything here:

https://wiki.haskell.org/Typeclassopedia

is replaced, in Elm, by just having an explicit module reference, so Maybe.andThen instead of andThen. No joke, that replaces essentially all of it, except some stuff that's not used that often.

You're way more experienced than me in this, but it seems to me that anywhere you're going to be replacing polymorphism is going to result in more typing. If you know the module that you want, then it is trivial, but the point of type classes (IIUC) is to write generic functions that can act on a variety of types.

To replace the non-trivial cases is going to require pattern matching, it seems. If your types change, then you are going to have to update things in multiple places.

But, like you said, it's not the end of the world. In many cases the intent will probably be clearer. Still, I'd rather have type classes than not.

Typeclasses aren't bad, that's for sure. I kinda want something as flexible as typeclasses and derive generic but no where near that complex. A big part of me says I could do well with just promising some JavaScript really really meets a type signature. Ports are great for side effects but I there might be room for this for pure functions?
You can do everything you can do in Haskell also in assembler. Haskell compiles down to assembler, where there is no Haskell.
Yes, you can, and the resulting code is an unreadable, unmaintainable mess after two weeks.