Précédent   Forum du club des développeurs et IT Pro > Autres langages > Langages fonctionnels > Haskell
Haskell Forum d'entraide sur la programmation en langage fonctionnel Haskell
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 14/11/2010, 23h01   #1
james-mi
Membre du Club
 
Inscription : mai 2005
Messages : 130
Détails du profil
Informations forums :
Inscription : mai 2005
Messages : 130
Points : 47
Points : 47
Par défaut Après caball install, comment charger mon module dans GHCi ? et dans runHaskell ?

Bonjour à tous,

je reviens ici après un long temps d'absence. J'ai un nouveau projet, que je compte faire en Haskell (j'ai programmé précédemment en OCaml). Pour cela, j'ai besoin d'utiliser Yaml, via un module que je trouvé sur HackageDB, à savoir data-object-yaml

contexte :
Je suis sous Windows, j'ai installé la plateforme pour Windows, et testé avec succès : GHCi, runHaskell, cabal

ce que j'ai fait :
Code :
cabal install data-object-yaml
ce que j'ai obtenu
tout ok apparemment : la commande ghc-pkg me renvoie :
Code :
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
J:/Program Files/Haskell Platform/2010.2.0.0\lib\package.conf.d:
    Cabal-1.8.0.6
    GLUT-2.1.2.1
    HTTP-4000.0.9
    HUnit-1.2.2.1
    OpenGL-2.2.3.0
    QuickCheck-2.1.1.1
    Win32-2.2.0.2
    array-0.3.0.1
    base-3.0.3.2
    base-4.2.0.2
    bin-package-db-0.0.0.0
    bytestring-0.9.1.7
    cgi-3001.1.7.3
    containers-0.3.0.0
    deepseq-1.1.0.0
    directory-1.0.1.1
    (dph-base-0.4.0)
    (dph-par-0.4.0)
    (dph-prim-interface-0.4.0)
    (dph-prim-par-0.4.0)
    (dph-prim-seq-0.4.0)
    (dph-seq-0.4.0)
    extensible-exceptions-0.1.1.1
    ffi-1.0
    fgl-5.4.2.3
    filepath-1.1.0.4
    (ghc-6.12.3)
    (ghc-binary-0.5.0.2)
    ghc-prim-0.2.0.0
    haskell-platform-2010.2.0.0
    haskell-src-1.0.1.3
    haskell98-1.0.1.1
    hpc-0.5.0.5
    html-1.0.1.2
    integer-gmp-0.2.0.1
    mtl-1.1.0.2
    network-2.2.1.7
    old-locale-1.0.0.2
    old-time-1.0.0.5
    parallel-2.2.0.1
    parsec-2.1.0.1
    pretty-1.0.1.1
    process-1.0.1.3
    random-1.0.0.2
    regex-base-0.93.2
    regex-compat-0.93.1
    regex-posix-0.94.2
    rts-1.0
    stm-2.1.2.1
    syb-0.1.0.2
    template-haskell-2.4.0.1
    time-1.1.4
    xhtml-3000.2.0.1
    zlib-0.5.2.0

J:\Documents and Settings\Toutlemonde\Application Data\ghc\i386-mingw32-6.12.3\package.conf.d:
    attempt-0.3.0
    convertible-text-0.3.0.6
    data-object-0.3.1.5
    data-object-yaml-0.3.3.1
    enumerator-0.4.2
    failure-0.1.0
    text-0.10.0.0
    transformers-0.2.2.0
    yaml-0.4.1
là où je bloque :
ben, je suppose que c'est un truc idiot qui bloque, mais :
- GHCi :
Code :
:module + Data.Object.Yaml
me renvoie :
Code :
1
2
3
<no location info>:
    Could not find module `Data.Object.Yaml':
      it is not a module in the current program, or in any known package.
-runHaskell test.hs
avec
Code :
import Data.Object.Yaml
me renvoie ... rien, il tourne indéfiniment ...

ce que j'ai consulté sans succès
realworldhaskell
et
learnyouahaskell.com
sans oublier Google, qui cette fois, n'a pas été mon ami ...


=> svp, quelqu'un peut me mettre sur la piste ?
james-mi est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/11/2010, 17h57   #2
Alp
Rédacteur
 
Avatar de Alp
 
Homme
Inscription : juin 2005
Messages : 8 586
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 24
Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

Informations forums :
Inscription : juin 2005
Messages : 8 586
Points : 11 172
Points : 11 172
Et en essayant avec :
Code :
1
2
runhaskell -package data-object-yaml tonfichier.hs
ou un truc du genre ? Idem avec ghci ?

Ou plus généralement, pour ton projet, tu fais ton import en haut et avec ghc, cette fois j'en suis sûr y'a une option -package, donc tu peux faire :
Code :
1
2
ghc -package data-object-yaml foo.hs
Ou alors carrément utiliser ghc --make foo.hs et ghc va deviner toutes les dépendances tout seul et les lier à ton code.
Alp est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/11/2010, 23h04   #3
james-mi
Membre du Club
 
Inscription : mai 2005
Messages : 130
Détails du profil
Informations forums :
Inscription : mai 2005
Messages : 130
Points : 47
Points : 47
Citation:
Envoyé par Alp Voir le message
Et en essayant avec :
Code :
1
2
runhaskell -package data-object-yaml tonfichier.hs
ou un truc du genre ? Idem avec ghci ?

Ou plus généralement, pour ton projet, tu fais ton import en haut et avec ghc, cette fois j'en suis sûr y'a une option -package, donc tu peux faire :
Code :
1
2
ghc -package data-object-yaml foo.hs
Ou alors carrément utiliser ghc --make foo.hs et ghc va deviner toutes les dépendances tout seul et les lier à ton code.
Merci de l'aide.

En fait, aujourd'hui, j'ai bien progressé. ce qui ne marchait par hier fonctionne aujourd'hui. Entre temps, je n'ai fait qu'éteindre et allumer l'ordi. Donc je suppose qu'un fichier de configuration s'est mis à jour dans ce processus.

Donc la solution, c'est de tout fermer et tout relancer après un cabal install. Il doit y avoir plus joli, mais ça ira pour l'instant.

Néanmoins, toujours bloqué,mais un peu plus loin :

1. ce qui marche maintenant dans GHCi :
Code :
1
2
:m + Data.Object
:m + Data.Object.Yaml
conduit à :
Code :
Prelude Data.List Data.Object Data.Object.Yaml>
ce qui est de bon augure
puis :
renvoie :
Code :
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
data Object key val
  = Mapping [(key, Object key val)]
  | Sequence [Object key val]
  | Scalar val
data ObjectExtractError
  = ExpectedScalar
  | ExpectedSequence
  | ExpectedMapping
  | MissingKey String
data Scalar
  = Numeric Rational
  | Text text-0.10.0.0:Data.Text.Internal.Text
  | Binary Data.ByteString.Internal.ByteString
  | Bool Bool
  | Timestamp time-1.1.4:Data.Time.Clock.UTC.UTCTime
  | Null
type ScalarObject = Object String Scalar
type StringObject = Object String String
type TextObject =
  Object
    text-0.10.0.0:Data.Text.Internal.Text
    text-0.10.0.0:Data.Text.Internal.Text
fromMapping ::
  (Control.Failure.Failure ObjectExtractError m) =>
  Object k v -> m [(k, Object k v)]
fromScalar ::
  (Control.Failure.Failure ObjectExtractError m) => Object k v -> m v
fromSequence ::
  (Control.Failure.Failure ObjectExtractError m) =>
  Object k v -> m [Object k v]
lookupMapping ::
  (Show k, Eq k, Control.Failure.Failure ObjectExtractError m) =>
  k -> [(k, Object k v)] -> m [(k, Object k v)]
lookupObject ::
  (Show k, Eq k, Control.Failure.Failure ObjectExtractError m) =>
  k -> [(k, Object k v)] -> m (Object k v)
lookupScalar ::
  (Show k, Eq k, Control.Failure.Failure ObjectExtractError m) =>
  k -> [(k, Object k v)] -> m v
lookupSequence ::
  (Show k, Eq k, Control.Failure.Failure ObjectExtractError m) =>
  k -> [(k, Object k v)] -> m [Object k v]
mapKeys ::
  (keyIn -> keyOut) -> Object keyIn val -> Object keyOut val
mapKeysValues ::
  (keyIn -> keyOut)
  -> (valIn -> valOut)
  -> Object keyIn valIn
  -> Object keyOut valOut
mapKeysValuesA ::
  (Control.Applicative.Applicative f) =>
  (keyIn -> f keyOut)
  -> (valIn -> f valOut)
  -> Object keyIn valIn
  -> f (Object keyOut valOut)
mapKeysValuesM ::
  (Monad m) =>
  (keyIn -> m keyOut)
  -> (valIn -> m valOut)
  -> Object keyIn valIn
  -> m (Object keyOut valOut)
mapValues ::
  (valIn -> valOut) -> Object key valIn -> Object key valOut
ce qui ressemble à quelque chose qui m'intéresse, bien que je suis très loin de tout comprendre.

puis un :
Code :
Prelude Data.List Data.Object Data.Object.Yaml> Scalar 1
renvoie :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
Loading package bytestring-0.9.1.7 ... linking ... done.
Loading package Win32-2.2.0.2 ... linking ... done.
Loading package old-locale-1.0.0.2 ... linking ... done.
Loading package time-1.1.4 ... linking ... done.
Loading package array-0.3.0.1 ... linking ... done.
Loading package containers-0.3.0.0 ... linking ... done.
Loading package deepseq-1.1.0.0 ... linking ... done.
Loading package failure-0.1.0 ... linking ... done.
Loading package text-0.10.0.0 ... linking ... done.
Loading package data-object-0.3.1.5 ... linking ... done.
Scalar 1
it :: Object key Integer
ça a une bonne tête, bien que je ne connaisse pas le début du commencement de tous ces packages
et ainsi de suite :
Code :
Mapping [("fj",Scalar 3),("ghkhk",Scalar 5)]
2.1 là où je bloque (1/2):
il y a un runtest fourni avec mon package data-object-yaml-0.3.3.1.tar.gz :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Prelude Data.List Data.Object Data.Object.Yaml> :load "runtests.hs"


runtests.hs:3:7:
    Could not find module `Test.Framework.Providers.HUnit':
      Use -v to see a list of the files searched for.
Failed, modules loaded: none.
Prelude Data.List Data.Object Data.Object.Yaml> :m + test.Framework.Providers.HUnit
syntax:  :module [+/-][*]M1 ...[*]Mn
Prelude Data.List Data.Object Data.Object.Yaml> :m + Test.Framework.Providers.HUnit


<no location info>:
    Could not find module `Test.Framework.Providers.HUnit':
      it is not a module in the current program, or in any known package.
2.2 là où je bloque (2/2):
au diable le runtest, ce qui m'intéresse, c'est la fonction decodeFile

Code - **en gras, la fonction decodeFile** :
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
:browse Data.Object.Yaml
class (Eq a) => IsYamlScalar a where
  fromYamlScalar :: YamlScalar -> a
  toYamlScalar :: a -> YamlScalar
data ParseException
  = NonScalarKey
  | UnknownAlias {_anchorName :: Text.Libyaml.AnchorName}
  | UnexpectedEvent {_received :: Maybe Text.Libyaml.Event,
                     _expected :: Maybe Text.Libyaml.Event}
  | InvalidYaml (Maybe String)
type YamlObject = Data.Object.Object YamlScalar YamlScalar
data YamlScalar
  = YamlScalar {value :: Data.ByteString.Internal.ByteString,
                tag :: Text.Libyaml.Tag,
                style :: Text.Libyaml.Style}
data ParseException
  = ... | UnknownAlias {_anchorName :: Text.Libyaml.AnchorName} | ...
data ParseException
  = ...
  | UnexpectedEvent {..., _expected :: Maybe Text.Libyaml.Event}
  | ...
data ParseException
  = ...
  | UnexpectedEvent {_received :: Maybe Text.Libyaml.Event, ...}
  | ...
decode ::
  (Control.Failure.Failure ParseException m,
   IsYamlScalar k,
   IsYamlScalar v) =>
  Data.ByteString.Internal.ByteString -> m (Data.Object.Object k v)
decodeFile ::
  (Control.Failure.Failure ParseException m,
   IsYamlScalar k,
   IsYamlScalar v) =>
  FilePath -> IO (m (Data.Object.Object k v))
encode ::
  (IsYamlScalar k, IsYamlScalar v) =>
  Data.Object.Object k v -> Data.ByteString.Internal.ByteString
encodeFile ::
  (IsYamlScalar k, IsYamlScalar v) =>
  FilePath -> Data.Object.Object k v -> IO ()
fromYamlObject ::
  (IsYamlScalar k, IsYamlScalar v) =>
  YamlObject -> Data.Object.Object k v
data YamlScalar = YamlScalar {..., style :: Text.Libyaml.Style}
data YamlScalar = YamlScalar {..., tag :: Text.Libyaml.Tag, ...}
toYamlObject ::
  (IsYamlScalar k, IsYamlScalar v) =>
  Data.Object.Object k v -> YamlObject
data YamlScalar
  = YamlScalar {value :: Data.ByteString.Internal.ByteString, ...}

hélas, dans GHCi :


Code :
1
2
3
4
5
6
7
8
9
10
11
>decodeFile "test_Yaml.txt"


<interactive>:1:0:
    No instance for (Control.Failure.Failure ParseException m)
      arising from a use of `decodeFile' at <interactive>:1:0-25
    Possible fix:
      add an instance declaration for
      (Control.Failure.Failure ParseException m)
    In the expression: decodeFile "test_Yaml.txt"
    In the definition of `it': it = decodeFile "test_Yaml.txt"
qui pourrait me débloquer ?
james-mi est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/11/2010, 01h08   #4
Alp
Rédacteur
 
Avatar de Alp
 
Homme
Inscription : juin 2005
Messages : 8 586
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 24
Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

Informations forums :
Inscription : juin 2005
Messages : 8 586
Points : 11 172
Points : 11 172
Pour le premier soucis, il te suffit d'installer HUnit. Le *test* dépend de HUnit, mais pas la lib, donc ça ne te force pas à l'installer quand t'installes la lib. Par contre c'est indispensable pour le test. Donc un cabal install HUnit devrait régler le soucis.

Le deuxième soucis est du au fait que, étant donnée la signature de decodeFile :
Code :
1
2
3
4
5
6
decodeFile ::
  (Control.Failure.Failure ParseException m,
   IsYamlScalar k,
   IsYamlScalar v) =>
  FilePath -> IO (m (Data.Object.Object k v))
Et que la seule instance de ParseException liée aux exceptions est de la classe Exception, en fouillant on trouve :
Code :
1
2
Exception e => Failure e IO
(ici : http://hackage.haskell.org/packages/...html#t:Failure )

Donc quand on fait :
Code :
1
2
decodeFile "test_Yaml.txt"
Ca nous oblige à ce que le "m" de la signature de decodeFile soit IO d'après ce que tu peux voir sur le lien sur le module Control.Failure. Or dans ton appel, rien ne contraint cela d'où l'erreur, je pense.

Bosse dans un fichier, en explicitant les signatures et surtout en remplaçant le "m" par IO, et charge ça dans ghci via :l, et tout devrait aller très bien.
Alp est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/11/2010, 22h55   #5
james-mi
Membre du Club
 
Inscription : mai 2005
Messages : 130
Détails du profil
Informations forums :
Inscription : mai 2005
Messages : 130
Points : 47
Points : 47
Citation:
Envoyé par Alp Voir le message
Pour le premier soucis, il te suffit d'installer HUnit. Le *test* dépend de HUnit, mais pas la lib, donc ça ne te force pas à l'installer quand t'installes la lib. Par contre c'est indispensable pour le test. Donc un cabal install HUnit devrait régler le soucis.
J'ai donc fait cabal install HUnit.

Je bloque encore, un peu plus loin :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Prelude> :load "runtests.hs"
[1 of 1] Compiling Main             ( runtests.hs, interpreted )
Ok, modules loaded: Main.
*Main> main
Loading package bytestring-0.9.1.7 ... linking ... done.
Loading package Win32-2.2.0.2 ... linking ... done.
Loading package old-locale-1.0.0.2 ... linking ... done.
Loading package time-1.1.4 ... linking ... done.
Loading package array-0.3.0.1 ... linking ... done.
Loading package containers-0.3.0.0 ... linking ... done.
Loading package syb-0.1.0.2 ... linking ... done.
Loading package base-3.0.3.2 ... linking ... done.
Loading package mtl-1.1.0.2 ... linking ... done.
Loading package regex-base-0.93.2 ... linking ... done.
Loading package regex-posix-0.94.2 ... linking ... ghc: unable to load package `regex-posix-0.94.2'
pourtant, regex-posix est installé :
Code :
1
2
3
4
5
6
7
8
J:/Program Files/Haskell Platform/2010.2.0.0\lib\package.conf.d:
...
    HUnit-1.2.2.1 **en fait il était déjà installé **
...
    regex-base-0.93.2
    regex-compat-0.93.1
    regex-posix-0.94.2
...
... étrange, non ? ...
pas davantage de succès avec ghc --make
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
> ghc --make runtests.hs > ghc_runtests.txt 2>&1

Linking runtests.exe ...
J:\Program Files\Haskell Platform\2010.2.0.0\lib\extralibs\regex-posix-0.94.2\ghc-6.12.3/libHSregex-posix-0.94.2.a(Wrap.o):fake:(.text+0x493): undefined reference to `regerror'
J:\Program Files\Haskell Platform\2010.2.0.0\lib\extralibs\regex-posix-0.94.2\ghc-6.12.3/libHSregex-posix-0.94.2.a(Wrap.o):fake:(.text+0x4e7): undefined reference to `regerror'
J:\Program Files\Haskell Platform\2010.2.0.0\lib\extralibs\regex-posix-0.94.2\ghc-6.12.3/libHSregex-posix-0.94.2.a(Wrap.o):fake:(.text+0x158d): undefined reference to `regcomp'
J:\Program Files\Haskell Platform\2010.2.0.0\lib\extralibs\regex-posix-0.94.2\ghc-6.12.3/libHSregex-posix-0.94.2.a(Wrap.o):fake:(.text+0x15a9): undefined reference to `regfree'
J:\Program Files\Haskell Platform\2010.2.0.0\lib\extralibs\regex-posix-0.94.2\ghc-6.12.3/libHSregex-posix-0.94.2.a(Wrap.o):fake:(.text+0x1787): undefined reference to `regexec'
J:\Program Files\Haskell Platform\2010.2.0.0\lib\extralibs\regex-posix-0.94.2\ghc-6.12.3/libHSregex-posix-0.94.2.a(Wrap.o):fake:(.text+0x1cff): undefined reference to `regexec'
J:\Program Files\Haskell Platform\2010.2.0.0\lib\extralibs\regex-posix-0.94.2\ghc-6.12.3/libHSregex-posix-0.94.2.a(Wrap.o):fake:(.text+0x1e6a): undefined reference to `regexec'
J:\Program Files\Haskell Platform\2010.2.0.0\lib\extralibs\regex-posix-0.94.2\ghc-6.12.3/libHSregex-posix-0.94.2.a(Wrap.o):fake:(.text+0x3f17): undefined reference to `regexec'
J:\Program Files\Haskell Platform\2010.2.0.0\lib\extralibs\regex-posix-0.94.2\ghc-6.12.3/libHSregex-posix-0.94.2.a(Wrap.o):fake:(.text+0x44a1): undefined reference to `regexec'
J:\Program Files\Haskell Platform\2010.2.0.0\lib\extralibs\regex-posix-0.94.2\ghc-6.12.3/libHSregex-posix-0.94.2.a(Wrap.o):fake:(.text+0x44fa): more undefined references to `regexec' follow
collect2: ld returned 1 exit status




quant à la suite de ton message, ça vole très haut pour moi, misérable ver de terre dans le monde Haskell, loin d'avoir tout compris aux monads ... je creuse, je creuse, mais pas encore très vif le misérable ver de terre ...
james-mi est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/11/2010, 23h25   #6
Alp
Rédacteur
 
Avatar de Alp
 
Homme
Inscription : juin 2005
Messages : 8 586
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 24
Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

Informations forums :
Inscription : juin 2005
Messages : 8 586
Points : 11 172
Points : 11 172
Pour l'erreur que tu as liée aux regex, je crois qu'il te manque la bibliothèque C correspondant à la bibliothèque de regex utilisée par le package haskell que tu utilises. Je ne sais pas exactement laquelle c'est, mais il faut que tu trouves et que tu la mette à dispo de ghc dans un coin de ton Windows, et tu peux spécifier tout ça via les options --extra-lib-dirs et --extra-include-dirs quand il y a besoin.

Pour la deuxième partie, oui c'est compliqué, mais déjà familiarise toi un peu plus avec les monades et ça ira mieux. Tu comprendras l'essentiel : il faut que m soit IO dans la signature de decodeFile.
Alp est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/11/2010, 23h38   #7
james-mi
Membre du Club
 
Inscription : mai 2005
Messages : 130
Détails du profil
Informations forums :
Inscription : mai 2005
Messages : 130
Points : 47
Points : 47
Citation:
Envoyé par Alp Voir le message
Pour la deuxième partie, oui c'est compliqué, mais déjà familiarise toi un peu plus avec les monades et ça ira mieux. Tu comprendras l'essentiel : il faut que m soit IO dans la signature de decodeFile.

Bon, un peu au pif, après quelques tatonnements : ça marche !!!

Code :
1
2
3
4
5
6
7
8
import Data.Object
import Data.Object.Yaml

main :: IO ()
main = do
    fileData_IO <- decodeFile "test_Yaml.txt"::IO (IO (Data.Object.Object String String))
    fileData <- fileData_IO
    print fileData
puis, dans GHCi :
Code :
1
2
main
Sequence [Scalar "Casablanca",Scalar "Bourgogne Casablanca",Scalar "La R\232gle du jeu",Scalar "Titanic"]
gros progrès !!!
maintenant j'espère pouvoir jouer avec ...


le m'enquiquine

et en tous cas, un grand merci Alp !
james-mi est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/11/2010, 22h01   #8
james-mi
Membre du Club
 
Inscription : mai 2005
Messages : 130
Détails du profil
Informations forums :
Inscription : mai 2005
Messages : 130
Points : 47
Points : 47
Citation:
Envoyé par james-mi Voir le message
Bon, un peu au pif, après quelques tatonnements : ça marche !!!

...

et en tous cas, un grand merci Alp !
je veux le passer en [résolu] mais impossible d'éditer ...un admin / modo peut le faire ?
james-mi est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/11/2010, 22h35   #9
Alp
Rédacteur
 
Avatar de Alp
 
Homme
Inscription : juin 2005
Messages : 8 586
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 24
Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

Informations forums :
Inscription : juin 2005
Messages : 8 586
Points : 11 172
Points : 11 172
Si y'en a un qui passe par là il le fera

Content que ton soucis soit résolu, hésite pas à repasser si t'as d'autres questions.
(ou à venir sur #haskell.fr sur irc.freenode.net )
Alp est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/11/2010, 10h44   #10
viro
Nouveau Membre du Club
 
Inscription : octobre 2002
Messages : 36
Détails du profil
Informations personnelles :
Localisation : France

Informations forums :
Inscription : octobre 2002
Messages : 36
Points : 27
Points : 27
Tout de même, cette signature en IO (IO .... ) je la trouve tordue.

D'après Control.Failure, le m peut être aussi [] ou Maybe, je me demande ci ce n'est pas plus approprié.
viro est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/11/2010, 22h11   #11
james-mi
Membre du Club
 
Inscription : mai 2005
Messages : 130
Détails du profil
Informations forums :
Inscription : mai 2005
Messages : 130
Points : 47
Points : 47
Citation:
Envoyé par viro Voir le message
Tout de même, cette signature en IO (IO .... ) je la trouve tordue.

D'après Control.Failure, le m peut être aussi [] ou Maybe, je me demande ci ce n'est pas plus approprié.
Ben moi aussi. L'auteur m'a aimablement donné des indications (que je ne pige pas vraiment) :

Citation:
Envoyé par james-mi
> 1. Why so complex ? (IO (IO (Data.Object.Object String String))
> Well, you don't need to answer if it's too much of a neebie question, I may
> understand in some weeks of it, when I'm getting used with the whole thing
> -is the module the right one for my needs ? I've seen that you've written several, may
> be you would advice another one ?
Citation:
Envoyé par Michael Snoyman
Because the inner one is not necessarily IO. It could be Maybe or any
other instance of Failure. This is just a way or generically dealing
with parse errors. Error handling techniques can be a bit of a complex
topic unfortunately. You might want to read the Failure wiki page:
http://haskell.org/haskellwiki/Failure
I think this is the right module to use. An older version of
data-object-yaml, before the alias support code was added, will
probably address your order issue immediately. Otherwise, I don't know
how long it will take for Anton to get back to me.
james-mi est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/11/2010, 09h31   #12
viro
Nouveau Membre du Club
 
Inscription : octobre 2002
Messages : 36
Détails du profil
Informations personnelles :
Localisation : France

Informations forums :
Inscription : octobre 2002
Messages : 36
Points : 27
Points : 27
Citation:
Envoyé par james-mi Voir le message
Ben moi aussi. L'auteur m'a aimablement donné des indications (que je ne pige pas vraiment) :
Il dit que le type interne n'est pas forcément IO, mais n'importe lequel qui appartient aussi à la classe Failure. ( si on regarde Control.Failure, il y a IO, Maybe et [] de définis, mais rien empèche d'en ajouter soi-même )

Il explique que l'intérêt est de proposer un moyen générique(généralisé) de traiter les erreurs. Selon les propriétés du type interne utilisé, on peut probablement faire quelque chose de différent.

Dans le cas de decodeFile, tout ca me paraît relever du bazooka logiciel, parce qu'on a le choix entre:
(rappel)
Code :
(Failure ParseException m, IsYamlScalar k, IsYamlScalar v) => FilePath -> IO (m (Object k v))
m peut donc être IO, Maybe ou [] ce qui donne
1.
Code :
(IsYamlScalar k, IsYamlScalar v) => FilePath -> IO (IO (Object k v))
2.
Code :
(IsYamlScalar k, IsYamlScalar v) => FilePath -> IO (Maybe (Object k v))
3.
Code :
(IsYamlScalar k, IsYamlScalar v) => FilePath -> IO ([Object k v])
en faisant

Code :
res <- decodeFile ......
1. En cas d'erreur, une exception sera générée, à intercepter par catch, handle, ou une fonction du genre.
2. En cas d'erreur, on récupère Nothing, sinon Just obj -- obj étant l'objet décodé.
3. En cas d'erreur, on récupère [], sinon [obj] -- obj étant l'objet décodé. (ici, dans une liste d'un seul élémént)


Note, dans le cas 1, on peut remplacer

Code :
1
2
action_a_faire <- decodeFile ....
resultat <- action_a_faire
par

Code :
resultat <- join $ decodeFile ......

A mon avis dans ton cas le mieux est de faire avec Maybe:
Code :
1
2
3
4
5
6
7
main :: IO ()
main = do
    fileData_Maybe <- decodeFile "test_Yaml.txt"  -- a mon avis pas besoin de la signature
    case fileData_Maybe of
      Nothing       -> putStrLn "ooops, ca a pas marche."
      Just fileData -> print fileData
viro est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/11/2010, 23h17   #13
james-mi
Membre du Club
 
Inscription : mai 2005
Messages : 130
Détails du profil
Informations forums :
Inscription : mai 2005
Messages : 130
Points : 47
Points : 47
Citation:
Envoyé par viro Voir le message
Il dit que le type interne n'est pas forcément IO, mais n'importe lequel qui appartient aussi à la classe Failure.
...
Code :
resultat <- join $ decodeFile ......
Ok, je prends bonne note de tout ça

Citation:
Envoyé par viro Voir le message
A mon avis dans ton cas le mieux est de faire avec Maybe:
Code :
1
2
3
4
5
6
7
main :: IO ()
main = do
    fileData_Maybe <- decodeFile "test_Yaml.txt"  -- a mon avis pas besoin de la signature
    case fileData_Maybe of
      Nothing       -> putStrLn "ooops, ca a pas marche."
      Just fileData -> print fileData
ça coince :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[1 of 1] Compiling Main             ( jmc_test_decode-encode File.hs, interpreted )

jmc_test_decode-encode File.hs:25:22:
    Ambiguous type variable `k' in the constraints:
      `IsYamlScalar k'
        arising from a use of `decodeFile'
                     at jmc_test_decode-encode File.hs:25:22-47
      `Show k'
        arising from a use of `print'
                     at jmc_test_decode-encode File.hs:28:23-36
    Probable fix: add a type signature that fixes these type variable(s)

jmc_test_decode-encode File.hs:25:22:
    Ambiguous type variable `v' in the constraints:
      `IsYamlScalar v'
        arising from a use of `decodeFile'
                     at jmc_test_decode-encode File.hs:25:22-47
      `Show v'
        arising from a use of `print'
                     at jmc_test_decode-encode File.hs:28:23-36
    Probable fix: add a type signature that fixes these type variable(s)

mais ça fonctionne avec
Code :
1
2
3
4
5
6
main :: IO ()
main = do
    fileData_Maybe <- decodeFile "test_Yaml_in.txt"  -- a mon avis pas besoin de la signature // OK, je la mets plus simple plus loin
    case fileData_Maybe of
      Nothing       -> putStrLn "ooops, ca a pas marche."
      Just fileData -> print (fileData::Data.Object.Object String String)
et je suis d'accord que c'est plus simple de gérer le Maybe ...
merci pour l'astuce
james-mi est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/11/2010, 17h17   #14
james-mi
Membre du Club
 
Inscription : mai 2005
Messages : 130
Détails du profil
Informations forums :
Inscription : mai 2005
Messages : 130
Points : 47
Points : 47
Et même un peu plus simple :

Code :
1
2
3
4
5
6
7
8
9
10
import Data.Object
import Data.Object.Yaml


main :: IO ()
main = do
    fileData_Maybe <- decodeFile "sandbox.yml"
    case fileData_Maybe of
      Nothing       -> putStrLn "ooops, ca a pas marche."
      Just fileData -> print (fileData::StringObject)
Je passe en résolu
james-mi est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Cette discussion est résolue.
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 20h23.


 
 
 
 
Partenaires

Hébergement Web