From corentin.dupont at gmail.com Mon Oct 29 06:09:43 2007 From: corentin.dupont at gmail.com (Dupont Corentin) Date: Mon Oct 29 06:07:17 2007 Subject: [Haskell-fr] Fractional etc... Message-ID: <18a05e6b0710290309qff6a121wb06ce746fadb25d2@mail.gmail.com> 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 :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 :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 From corentin.dupont at gmail.com Mon Oct 29 07:02:50 2007 From: corentin.dupont at gmail.com (Dupont Corentin) Date: Mon Oct 29 07:00:21 2007 Subject: [Haskell-fr] Re: Fractional etc... In-Reply-To: <20071029104150.GA26568@nic.fr> References: <18a05e6b0710290309qff6a121wb06ce746fadb25d2@mail.gmail.com> <20071029104150.GA26568@nic.fr> Message-ID: <18a05e6b0710290402i3cfcb163r264d0ce27e0acc86@mail.gmail.com> J'ai ghci 6.6.1. Ce code ne passe pas: *Prelude> let m = 5 Prelude> map (/m) [0..10] :1:4: No instance for (Fractional Integer) arising from use of `/' at :1:4-7 *par contre ?a ?a passe dans ghci: *Prelude> let foo m = map (/m) [0..10] Prelude> foo 5 [0.0,0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.6,1.8,2.0]* Mais... Bien sur: *Prelude> let n = 5* *Prelude> let foo m = map (/m) [0..10] Prelude> foo n* Ne passe pas plus! * * On 10/29/07, Stephane Bortzmeyer wrote: > On Mon, Oct 29, 2007 at 11:09:43AM +0100, > Dupont Corentin wrote > a message of 43 lines which said: > > > let m = 5 > > map (/m) [0..10] > > > > il me sort: > > No instance for (Fractional Integer) > > Quelle version ? Avec ghci 6.6, c'est accept? sans probl?me. (J'ai > essay? avec let et aussi avec : > > foobar m = > map (/m) [0..10] > > main = do > print (foobar 5) > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-fr/attachments/20071029/289298d0/attachment.htm From chaddai.fouche at gmail.com Mon Oct 29 07:44:44 2007 From: chaddai.fouche at gmail.com (=?ISO-8859-1?Q?Chadda=EF_Fouch=E9?=) Date: Mon Oct 29 07:42:14 2007 Subject: [Haskell-fr] Fractional etc... In-Reply-To: <18a05e6b0710290309qff6a121wb06ce746fadb25d2@mail.gmail.com> References: <18a05e6b0710290309qff6a121wb06ce746fadb25d2@mail.gmail.com> Message-ID: Le 29/10/07, Dupont Corentin a ?crit : > > let m = 5 > map (/m) [0..10] > > il me sort: > No instance for (Fractional Integer) > arising from use of `/' at :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]) > C'est normal, car GHCi est oblig? de typer 5 sans autres informations, il lui donne donc le type par d?faut pour un litt?ral entier : Integer. Comme ensuite tu utilises (/) qui ne prend pas un Integer comme op?rande... Par contraste : map (/5) [0..10] L?, GHCi a plus d'information sur le typage de 5, il sait qu'il doit s'agir d'un Fractional, il lui donne donc le type Fractional par d?faut, c'est ? dire Double. Dans un v?ritable programme, ce probl?me n'appara?t pas, car GHC dispose toujours de meilleures contraintes de typage (ou la variable n'est pas utilis?e). Il n'y a pas vraiment de rem?de au probl?me, except? de mettre un devin dans GHCi, ou peut-?tre de retarder la compilation des lets... (mais jusqu'? quand ?) -- Jeda? From popavdan at yahoo.com Mon Oct 29 14:21:04 2007 From: popavdan at yahoo.com (Dan Popa) Date: Mon Oct 29 14:18:38 2007 Subject: [Haskell-fr] Fractional etc... In-Reply-To: <18a05e6b0710290309qff6a121wb06ce746fadb25d2@mail.gmail.com> Message-ID: <392608.60401.qm@web36506.mail.mud.yahoo.com> 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 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 :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 :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@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 From corentin.dupont at gmail.com Tue Oct 30 04:49:03 2007 From: corentin.dupont at gmail.com (Dupont Corentin) Date: Tue Oct 30 04:46:31 2007 Subject: [Haskell-fr] Fractional etc... In-Reply-To: <392608.60401.qm@web36506.mail.mud.yahoo.com> References: <18a05e6b0710290309qff6a121wb06ce746fadb25d2@mail.gmail.com> <392608.60401.qm@web36506.mail.mud.yahoo.com> Message-ID: <18a05e6b0710300149w36ae5389l63747faf5ef09aa9@mail.gmail.com> 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 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 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 :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 :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@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@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 From chaddai.fouche at gmail.com Tue Oct 30 06:50:47 2007 From: chaddai.fouche at gmail.com (=?ISO-8859-1?Q?Chadda=EF_Fouch=E9?=) Date: Tue Oct 30 06:48:15 2007 Subject: [Haskell-fr] Fractional etc... In-Reply-To: <18a05e6b0710300149w36ae5389l63747faf5ef09aa9@mail.gmail.com> References: <18a05e6b0710290309qff6a121wb06ce746fadb25d2@mail.gmail.com> <392608.60401.qm@web36506.mail.mud.yahoo.com> <18a05e6b0710300149w36ae5389l63747faf5ef09aa9@mail.gmail.com> Message-ID: Le 30/10/07, Dupont Corentin a ?crit : > > 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? > No, you can't "divide a real by an integer", but you can introduce the integer in the reals and divide by this. divideByI :: (Fractional a, Integral b) => a -> b -> a divideByI a b = a / fromIntegral b -- Jeda?