What GHC-type system extensions should I learn first?

GHC has a whole zoo of system type extensions: multiparameter type classes, functional dependencies, rank-n-polymorphism, existential types, GADT, type families, region type variables, etc. etc. Which ones are probably the easiest to learn about the former? In addition, are these functions combined in some way, or are they all fairly different ideas, useful for completely different purposes?

+6
source share
2 answers

Good to learn early on is ScopedTypeVariables because they are very useful for debugging type problems in a function. When I get an error like Bause, I temporarily add type declarations for each of the function expressions. (Often you need to break up some expressions to see what is actually happening.) This usually helps me determine which expression is of a different type than I expected.

TypeFamilies more powerful than MultiParamTypeClasses , so you don't need the latter. When working with type families, you usually need to enable FlexibleContexts and FlexibleInstances so that you can recognize three pragmas for the price of one. FunctionalDependencies usually used with MultiParamTypeClasses , so you can ignore it now.

The GHC tells you very well when you need to enable Rank2Types or RankNTypes so that you can postpone training about this a bit later.

These are the ones I'll start with.


EDIT: Removed comment on avoiding StandaloneDeriving . (I was thinking about orphans.)

+7
source

Notice that I worked with Haskell for some time, I developed some of my own opinions on this issue. mhwombat ScopedTypeVariables suggestion was good. These days, this is usually the first thing I type when I start writing the Haskell module. Whenever the code gets a bit complicated, I like having a lot of type signatures to help me understand what I'm doing, and this extension allows me to write those that I couldn't otherwise. It can also significantly improve type errors. It also seems almost necessary when using other type system extensions.

I didn't really appreciate GADT too much until I learned a little about dependent programming languages. Note. I find it amazing how they can serve as evidence objects and how they can be limited by type indices.

GADTa works great with DataKinds , which creates fun-type indexes such as lists and gates. Now I can do things like expressing an indexed list as long as the tree is tall, not driving myself crazy using nested types of a higher order.

So far, I have not studied multiparameter class classes and functional dependencies. However, I came to understand the Edward Kmett reflection library, which uses them in its interface.

I have learned to have a healthy respect for overlapping and incoherent instances, and I mean that I never use them. Overlapping elements are a bit like macro programming with worse error messages, and incoherent ones are insane.

RankNTypes really strong. This is one of those things that are rarely needed, but when necessary, it is really important.

+2
source

All Articles