IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Haskell Discussion :

No instance for (Integral Float) ENCORE !


Sujet :

Haskell

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    113
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 113
    Points : 64
    Points
    64
    Par défaut No instance for (Integral Float) ENCORE !
    Bonjour, voici le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    import Data.Monoid
    import System.IO
    import System.Random
    import Graphics.Gloss
     
    main = do
            affiche 
     
    affiche = display  
    	 (InWindow
    	       "Pascal"
    		(300, 300)
    		(10, 10))
             black
             (picture)
     
    picture = pictures (listOfpoints n a i j ecart b coul)  -- ligne 17
        where
    	a = [1,1,1,2] :: [Float]
    	n = 91200
            j = 3
    	i = 1
    	ecart = 0
    	b = 0 :: Float
    	coul = 0 :: Float
     
    listOfpoints 0 _ _ _ _ _ _ = []
    listOfpoints n a i j ecart b coul = point : listOfpoints (n-1) a' i' j' ecart' b' coul'
        where
    	i' = calci i j
    	j' = calcj i j
    	ecart' = calce j' ecart
    	b' = calcb a j' ecart'
    	a' = a ++ [b']
    	coul' = teinte b'
            point = translate (fromIntegral i') (fromIntegral j') (color (myColor(coul')) 
     
    (circle 1.0))
     
    calci i j
    	|j == i = i + 1
    	|otherwise = i
     
    calcj i j 
    	|j == i = 0
    	|otherwise = j + 1
     
    calce j' ecart
    	|j' == 0 = ecart + 1
    	|otherwise = ecart
     
    calcb a j' ecart'
    	|fromIntegral j' == 0 = 1	
    	|otherwise = (a !! (fromIntegral j' - 1)) + (a !! (fromIntegral j' - fromIntegral 
     
    ecart'))`mod`2
     
    teinte b'
    	|b' < 128 = ((256`mod`(256 - 2*b'))`mod`13)
    	|otherwise = 0
     
    myColor coul' = ( [ca,cb,cc,cd,ce,cf,cg,ch,ci,cj,ck,cl,cm,cn,co,cp] !! abs(round(coul')) )
     
    ca = white
    cb = light(light yellow)
    cc = light yellow
    cd = yellow   
    ce = light(light orange)
    cf = light orange
    cg = orange
    ch = light (dark orange)
    ci = light red
    cj = red
    ck = dark red 
    cl = light violet
    cm = violet
    cn = light(light (dark violet))
    co = light ( dark violet)
    cp = blue
    Et voici le message:
    TestPascal.hs:17:21:
    No instance for (Integral Float)
    arising from a use of `listOfpoints'
    Possible fix: add an instance declaration for (Integral Float)
    In the first argument of `pictures', namely
    `(listOfpoints n a i j ecart b coul)'
    In the expression: pictures (listOfpoints n a i j ecart b coul)
    In an equation for `picture':
    picture
    = pictures (listOfpoints n a i j ecart b coul)
    where
    a = [1, ....] :: [Float]
    n = 91200
    j = 3
    i = 1
    ....

    Il m'est plus difficile de répondre aux exigences de langage que de trouver les bons algorithmes !
    Quel est le problème ici ?
    Merci d'avance.

  2. #2
    Expert éminent
    Avatar de Jedai
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2003
    Messages
    6 245
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Avril 2003
    Messages : 6 245
    Points : 8 586
    Points
    8 586
    Par défaut
    mod est un opérateur sur les entiers, donc l'utiliser sur un élément de a qui est une liste de flottant ne marche pas bien.

    Par ailleurs, tu utilises fromIntegral à tort et à travers, par exemple dans "a !! (fromIntegral j' - 1)", j' est un entier et tu veux l'utiliser comme un indice de liste, donc comme un entier... Donc ton fromIntegral convertit un entier en un entier. "fromIntegral j' == 0" est pas mal aussi...
    J'ai l'impression que pratiquement tous tes calculs pourraient se faire avec des entiers (logique si tu fais le triangle de Pascal) et tu convertirais juste à la fin pour la translation.

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    113
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 113
    Points : 64
    Points
    64
    Par défaut
    Si je passe tout en entiers( ce que j'avais au départ) ce n'est pas un message mais plusieurs messages d'erreurs que je doit gérer.
    Bon, je recommence le tout. voila:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    import Data.Monoid
    import System.IO
    import System.Random
    import Graphics.Gloss
     
    main = do
            affiche 
     
    affiche = display  
    	 (InWindow
    	       "Pascal"
    		(300, 300)
    		(10, 10))
             black
             (picture)
     
    picture = pictures (listOfpoints n a i j ecart b coul)  -- ligne 17
        where
    	a = [1,1,1,2]
    	n = 91200
            j = 3
    	i = 1
    	ecart = 0
    	b = 0
    	coul = 0
     
    listOfpoints 0 _ _ _ _ _ _ = []
    listOfpoints n a i j ecart b coul = point : listOfpoints (n-1) a' i' j' ecart' b' coul'
        where
    	i' = calci i j
    	j' = calcj i j
    	ecart' = calce j' ecart
    	b' = calcb a j' ecart'
    	a' = a ++ [b']
    	coul' = teinte b'
            point = translate i' j' (color (myColor(coul')) (circle 1.0))
     
    calci i j
    	|j == i = i + 1
    	|otherwise = i
     
    calcj i j 
    	|j == i = 0
    	|otherwise = j + 1
     
    calce j' ecart
    	|j' == 0 = ecart + 1
    	|otherwise = ecart
     
    calcb a j' ecart'
    	|fromIntegral j' == 0 = 1	
    	|otherwise = (a !! (j' - 1)) + (a !! (j' - ecart'))`mod`2
     
    teinte b'
    	|b' < 128 = ((256`mod`(256 - 2*b'))`mod`13)
    	|otherwise = 0
     
    myColor coul' = ( [ca,cb,cc,cd,ce,cf,cg,ch,ci,cj,ck,cl,cm,cn,co,cp] !! abs(round(coul')) )
     
    ca = white
    cb = light(light yellow)
    cc = light yellow
    cd = yellow   
    ce = light(light orange)
    cf = light orange
    cg = orange
    ch = light (dark orange)
    ci = light red
    cj = red
    ck = dark red 
    cl = light violet
    cm = violet
    cn = light(light (dark violet))
    co = light ( dark violet)
    cp = blue
    TestPascal.hs:28:70:
    Couldn't match expected type `Float'
    with actual type `Float -> Float'
    In the fourth argument of `listOfpoints', namely j'
    In the second argument of `( : )', namely
    listOfpoints (n - 1) a' i' j' ecart' b' coul'
    In the expression:
    point : listOfpoints (n - 1) a' i' j' ecart' b' coul'

    TestPascal.hs:33:22:
    Couldn't match expected type `Int' with actual type `a0 -> a0'
    In the second argument of `calcb', namely j'
    In the expression: calcb a j' ecart'
    In an equation for b': b' = calcb a j' ecart'

    TestPascal.hs:36:30:
    Couldn't match expected type `Float'
    with actual type `Float -> Float'
    In the second argument of `translate', namely j'
    In the expression:
    translate i' j' (color (myColor (coul')) (circle 1.0))
    In an equation for `point':
    point = translate i' j' (color (myColor (coul')) (circle 1.0))

    je modifie :
    point = translate (fromIntegral i') (fromIntegral j') (color (myColor(coul')) (circle 1.0)) (ce que j'avais fait).
    Et j'ai un nouveau message
    TestPascal.hs:17:21:
    No instance for (RealFrac a0) arising from a use of `listOfpoints'
    The type variable `a0' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
    instance RealFrac Double -- Defined in `GHC.Float'
    instance RealFrac Float -- Defined in `GHC.Float'
    instance Integral a => RealFrac (GHC.Real.Ratio a)
    -- Defined in `GHC.Real'
    In the first argument of `pictures', namely
    `(listOfpoints n a i j ecart b coul)'
    In the expression: pictures (listOfpoints n a i j ecart b coul)
    In an equation for `picture':
    picture
    = pictures (listOfpoints n a i j ecart b coul)
    where
    a = [1, ....]
    n = 91200
    j = 3
    i = 1
    ....

    TestPascal.hs:25:16:
    No instance for (Num a0) arising from the literal `0'
    The type variable `a0' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
    instance Num Double -- Defined in `GHC.Float'
    instance Num Float -- Defined in `GHC.Float'
    instance Integral a => Num (GHC.Real.Ratio a)
    -- Defined in `GHC.Real'
    ...plus five others
    In the expression: 0
    In an equation for `coul': coul = 0
    In an equation for `picture':
    picture
    = pictures (listOfpoints n a i j ecart b coul)
    where
    a = [1, ....]
    n = 91200
    j = 3
    i = 1
    ....

    Et maintenant je ne sais plus!

  4. #4
    Expert éminent
    Avatar de Jedai
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2003
    Messages
    6 245
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Avril 2003
    Messages : 6 245
    Points : 8 586
    Points
    8 586
    Par défaut
    round est une opération qui ne s'applique pas aux entiers (c'est poursuoi myColor voulait un RealFloat) :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    import Data.Monoid
    import System.IO
    import System.Random
    import Graphics.Gloss
     
    main = do
            affiche 
     
    affiche = display  
             (InWindow
                   "Pascal"
                    (300, 300)
                    (10, 10))
             black
             (picture)
     
    picture = pictures (listOfpoints n a i j ecart b coul)  -- ligne 17
        where
            a = [1,1,1,2]
            n = 10000
            j = 3
            i = 1
            ecart = 0
            b = 0
            coul = 0
     
    listOfpoints :: Int -> [Int] -> Int -> Int -> Int -> Int -> Int -> [Picture]
    listOfpoints 0 _ _ _ _ _ _ = []
    listOfpoints n a i j ecart b coul = point : listOfpoints (n-1) a' i' j' ecart' b' coul'
        where
            i' = calci i j
            j' = calcj i j
            ecart' = calce j' ecart
            b' = calcb a j' ecart'
            a' = a ++ [b']
            coul' = teinte b'
            point = translate (fromIntegral i') (fromIntegral j') (color (myColor(coul')) (circle 1.0))
     
    calci i j
            |j == i = i + 1
            |otherwise = i
     
    calcj i j 
            |j == i = 0
            |otherwise = j + 1
     
    calce j' ecart
            |j' == 0 = ecart + 1
            |otherwise = ecart
     
    calcb a j' ecart'
            |j' == 0 = 1        
            |otherwise = a !! (j' - 1) + (a !! (j' - ecart' - 1) `mod` 2)
     
    teinte b'
            |b' < 128 = ((256`mod`(256 - 2*b'))`mod`13)
            |otherwise = 0
     
    myColor coul' = [ca,cb,cc,cd,ce,cf,cg,ch,ci,cj,ck,cl,cm,cn,co,cp] !! (abs coul' `mod` 16 )
     
    ca = white
    cb = light(light yellow)
    cc = light yellow
    cd = yellow   
    ce = light(light orange)
    cf = light orange
    cg = orange
    ch = light (dark orange)
    ci = light red
    cj = red
    ck = dark red 
    cl = light violet
    cm = violet
    cn = light(light (dark violet))
    co = light ( dark violet)
    cp = blue
    Il y avait également un problème avec calcb car "j' - ecart'" était parfois égal à la longueur de a. J'ai juste ajouté un "-1" pour qu'il s'exécute sans erreur mais le résultat n'est pas la bonne figure. A toi de trouver où est le problème dans ton algorithme.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. No instance for (RealFrac Int)
    Par vasilpapa dans le forum Haskell
    Réponses: 0
    Dernier message: 06/06/2015, 15h08
  2. Problème a l'exécution du simple Job (Sql Server) de TOS for integration Data 5.3.3
    Par newvitch dans le forum Exécution et industrialisation
    Réponses: 1
    Dernier message: 08/06/2013, 15h29
  3. Réponses: 6
    Dernier message: 11/01/2011, 18h29
  4. No action instance for path could be created
    Par yayamo dans le forum Struts 1
    Réponses: 15
    Dernier message: 11/05/2007, 12h17
  5. No action instance for path /action could be created
    Par gentil dans le forum Struts 1
    Réponses: 20
    Dernier message: 10/04/2007, 13h54

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo