[Haskell-cafe] Re: Difference between div and /
Henning Thielemann
schlepptop at henning-thielemann.de
Wed Jun 2 10:11:27 EDT 2010
Sorry, I missed this post.
Maciej Piechotka schrieb:
> Well - i tried to write some package dealing with distributions etc.
>
> If you have something like that:
>
> instance ... => Distribution (Linear a) a where
> rand (Linear f s) g =
> let (gf, gt) = genRange g
> (v, g') = next g
> in (g', f + (fromIntegral v * s) / fromIntegral (gt - gf))
>
> (I haven't check it but IMHO it is right implementation)
>
> Now I have following options:
>
> - Implement per Int/Int8/...
> - Implement IntegerLinear and FractionalLinear separatly
That is, what you need is a general division with rounding. But you
might more generally want a custom type class with a method that selects
an element from a set for given parameters gf, gt, v. This way, you
could also handle distributions on Enumeration types. You certainly you
do not want, say a division operation on Monday, Tuesday, ..., Sunday,
but having a probability distribution of weekdays is very reasonable.
Btw. you may want to have a look at:
http://hackage.haskell.org/package/probability
More information about the Haskell-Cafe
mailing list