[Haskell-cafe] Cons of -XUndecidableInstances

Scott Lawrence bytbox at gmail.com
Mon Jun 6 09:36:54 CEST 2011


On 06/06/2011 03:13 AM, Scott Lawrence wrote:
>> 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.
> No, your types are right.
> 

Or not.

  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

(Let me know if I'm doing something insane again - thanks.)

But this doesn't allow me to specialize for markov models. Seems to me
that to do that, I'd have to store data - and once I'm using a datatype
for markov models:

  data Markov a = Markov
    { lexemeSet :: Set a
    , matrix    :: Map [a] (ProbDist a)
    }

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?)

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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 900 bytes
Desc: OpenPGP digital signature
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110606/134bbdae/attachment.pgp>


More information about the Haskell-Cafe mailing list