[Haskell-cafe] Cons of -XUndecidableInstances

Yitzchak Gale gale at sefer.org
Mon Jun 6 08:57:22 CEST 2011

Scott Lawrence wrote:
> I'm modelling text in a markov-model-like way. I have an actual markov
> model (albeit one in which X_n depends on a fixed range X_n-1 ..
> X-n-k). I'm vaguely anticipating the presence of other models:
>  class Model m a | m -> a where
>    lexemes :: m -> Set a
>    genFunc :: m -> [a] -> ProbDist a

Generally, we don't start out with a type class. Type classes are
great for the special situations in which they are needed (although
you can do pretty well without them even then), but first
let's get the basic concepts.

Perhaps a model is just a function:

type Model a = Ord a => Set a -> [a] -> ProbDist a

or something like that.

> Having that working, I'm trying to estimate the information entropy of a model
>  entropy :: (Model m) => m -> Double

Perhaps just a function:

entropy :: Model a -> Double

I still don't know enough details about what you're doing,
so my types are probably off. But I hope you get the idea.

If that's not general enough, you may introduce more functions, or
some data types. Those give you a huge amount of power - remember
that data types can take multiple type parameters (without any
GHC extension), they can have functions as their parameters, etc.

Or, perhaps you'll even get to the point where you'll need a type class,
but that's pretty far down the road, and what you would need it
for is very different than what a class is in OOP - they are different

Hope this helps,

More information about the Haskell-Cafe mailing list