[Haskell-cafe] Cons of -XUndecidableInstances

Yitzchak Gale gale at sefer.org
Mon Jun 6 09:56:52 CEST 2011


Scott Lawrence wrote:
>  type Model a = (Ord a) => Set a -- the set of lexemes
>                         -> [a] -- the original text to model
>                         -> [a] -- list of previous lexemes
>                         -> ProbDist a -- the next lexeme
>
> and then
>
>  entropy :: Model a -> Set a -> [a] -> Double
>
> or perhaps more simply
>
>  entropy :: [a] -> ProbDist a -> Double

Those all look reasonable.

> Then in order to get a consistent interface to various models, I'm going
> to need a typeclass. (Which is required to use a single function name on
> multiple datatypes, yes?)

Why is it important to use the same function name? If you
have two different functions that do two different things, they
can have two different names.

If further down the line you need to write a function that is independent
of the model, the types of its arguments will show you what you
need to do.

> I suppose the alternative is something like
>
>  data Model a = Markov {...} | OtherModel
>
> Is that the functional solution? It seems to preclude the possibility of
> separating the markov-specialized code and the other specialized code.

Right, it doesn't sound like that's the way to go here.

Regards,
YItz



More information about the Haskell-Cafe mailing list