retourner un (Maybe Float -> Float -> Float)
Bonjour,
Je démarre tout justeavec Haskell. Je développe quelques petits programmes pour me faire la main. J'ai fait un evaluateur de notation polonaise inversée qui fonctionne bien mais j'aimerais l'améliorer avec l'utilisation de Maybe notamment. Et c'est là que je butte.
Je voudrais avoir une fonction qui me retourne une fonction Float-> Float->Float à partir d'un nom de fonction ( (+) pour "+" par exemple)
et rien (Nothing) si la fonction n'est pas connue.
Mon implémentation actuelle est la suivante
Code:
1 2 3 4 5 6 7
| operation :: String -> Maybe Float -> Float -> Float
operation op
| op == "+" = Just (+)
| op == "-" = Just (-)
| op == "*" = Just (*)
| op == "/" = Just (/)
| otherwise = Nothing |
Mais la compilation échoue :
rpn.hs:64:18:
Couldn't match expected type `Maybe Float -> Float -> Float'
with actual type `Maybe a0'
In the expression: Nothing
In an equation for `operation':
operation op
| op == "+" = Just (+)
| op == "-" = Just (-)
| op == "*" = Just (*)
| op == "/" = Just (/)
| otherwise = Nothing
je ne comprends pas ce que je loupe. Dois je typer explictement le Nothing ? si oui comment ?
Ou alors n'ai je pas bien compris le Maybe ?
Merci d'avance pour votre aide
Olivier