Je ne comprends pas quel est le problème. 'a' n'est pas un booléen et ne devrait pas être un booléen. Alors, pourquoi Bool est-il attendu?Erreur Haskell: Impossible de faire correspondre le type attendu `Bool 'au type inféré` IO b'
code:
probablyPrime n 0 = False
probablyPrime n t =
do a <- randomRIO(3, n-1 :: Integer)
let comp = defComp(a,n)
let ret = (not comp) && (probablyPrime n t-1)
return ret
defComp a n = xcon1 && xcon2
where (s,m) = findsm n
x = a^m `mod` n
xcon1 = x /= 1 || x /= n-1
xcon2 = comploop x n s
comploop x n 0 = False
comploop x n s = x1 || (comploop x n (s-1))
where x1 = (x^2 `mod` n) == 1
findsm n = (s,m)
where m = findm n
s = n/m
findm n = m
where f = (logBase 2 n) - (truncate (logBase 2 n))
m' = 2^f
m = m_ify m'
m_ify m | m mod 1 == 0 = m
| otherwise = m_ify (m*2)
Erreur:
Couldn't match expected type `Bool' against inferred type `IO b'
In a stmt of a 'do' expression:
a <- randomRIO (3, n - 1 :: Integer)
In the expression:
do { a <- randomRIO (3, n - 1 :: Integer);
let comp = defComp ...;
let ret = (not comp) && (probablyPrime n t - 1);
return ret }
In the definition of `probablyPrime':
probablyPrime n t
= do { a <- randomRIO (3, n - 1 :: Integer);
let comp = ...;
let ret = ...;
.... }
Vous devez faire attention à la syntaxe de votre appel de fonction. Vous utilisez 'f (x, y)' plusieurs fois, mais cela n'a presque jamais raison dans Haskell - il applique la fonction à un seul tuple; vous voulez 'f x y'. –
(en fait, pour être plus précis, vous * le * voulez pour 'randomRIO' mais pas 'defComp') –
Y a-t-il un problème de base avec la logique ici? Si vous êtes '&&' -ing 'probablementPrime n t' tout le long de' t = 0' et 'probablementPrime n 0' est' False', alors vous aurez toujours 'False'. –