Je rappelle pour ceux qui lisent que OCaml ou Haskell déduisent les types et vérifient leur cohérence sans aucune annotation de l'utilisateur. En pratique on écrit souvent ces types déduits dans un fichier, mais le système est capable de générer un canvas qu'il suffit de compléter.
OCaml sait faire ça, pas Haskell :
dataFoodataBarclassClaaaasseawhereclaaaasse::a->IO()instanceClaaaasseFoowhereclaaaasse_=putStrLn"Je suis Foo"instanceClaaaasseBarwhereclaaaasse_=putStrLn"Je suis Bar"main=claaaasseundefined
Le compilo répond :
Ambiguous type variable ‘a0’ arising from a use of ‘claaaasse’
prevents the constraint ‘(Claaaasse a0)’ from being solved.
Probable fix: use a type annotation to specify what ‘a0’ should be.
These potential instances exist:
instance Claaaasse Bar -- Defined at foo.hs:7:10
instance Claaaasse Foo -- Defined at foo.hs:5:10
• In the expression: claaaasse undefined
In an equation for ‘main’: main = claaaasse undefined
[^] # Re: Un peu déçu par Rust
Posté par foobarbazz . En réponse au journal Un print(1 + "3a"), ça nous inspire comment ?. Évalué à 1.
OCaml sait faire ça, pas Haskell :
Le compilo répond :
En précisant le type de undefined ça marche.