[Haskell-fr] Fractional etc...

Dupont Corentin corentin.dupont at gmail.com
Tue Oct 30 04:49:03 EDT 2007


There must be a way to divide a real by an integer??
My integer is eventually a "number of elements" as in the exemple of Dan.
How would you compute a mean then?


On 10/29/07, Dan Popa <popavdan at yahoo.com> wrote:
>
> Why don't you try :
> > map (/5.0) [0.0 .. 10.0]
> >
> > let m = 5.0
> > map (/m) [0.0 .. 10.0]
> >
> I have a similar problem trying a divison by a  length
> of a list. Finaly I have to build a version of length
> called len:
>
> len [] = 0.0
> len (h:t)  = 1.0 + len t
>
> Dan
>
>
> --- Dupont Corentin <corentin.dupont at gmail.com> wrote:
>
> > Salut,
> > J'ai vraiment du mal à mettre au point un petit
> > programme...
> > Il me sort souvent des problèmes du style :
> >
> >   No instance for (Fractional Integer)
> >      arising from use of `/' at <interactive>:1:4-7
> >   Possible fix: add an instance declaration for
> > (Fractional Integer)
> >
> > Par exemple sous ghci si je fait:
> >
> > map (/5) [0..10]
> >
> > tout se passe bien.
> > Mais si je me dit "tiens je voudrais bien paramétrer
> > le 5":
> >
> > let m = 5
> > map (/m) [0..10]
> >
> > il me sort:
> >     No instance for (Fractional Integer)
> >       arising from use of `/' at <interactive>:1:4-7
> >     Possible fix: add an instance declaration for
> > (Fractional Integer)
> >     In the first argument of `map', namely `(/ m)'
> >     In the expression: map ((/ m)) ([0 .. 10])
> >     In the definition of `it': it = map ((/ m)) ([0
> > .. 10])
> >
> >
> > Pourtant les 2 codes me sembles assez équivalents!!!
> > Je peux utiliser des "fromInteger", ce qui résout
> > temporairement le problème.
> >
> > Je me retrouve par la suite avec des (de mémoire)
> > Infered type : Int
> > Expected type : Integer
> >
> > Ce qui me laisse dans le flou...
> >
> > a+
> > Corentin
> > _______________________________________________
> > Haskell-fr mailing list
> > Haskell-fr at haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-fr
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> _______________________________________________
> Haskell-fr mailing list
> Haskell-fr at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-fr
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-fr/attachments/20071030/832e8d98/attachment.htm


More information about the Haskell-fr mailing list