Skip to content

Instantly share code, notes, and snippets.

@vivax3794
Created March 26, 2020 15:52
Show Gist options
  • Save vivax3794/a69a8816ff7a86a55fcb1e814e91c7e1 to your computer and use it in GitHub Desktop.
Save vivax3794/a69a8816ff7a86a55fcb1e814e91c7e1 to your computer and use it in GitHub Desktop.
haskell cant get it to work...
test.hs:6:60: error:
• Couldn't match expected type ‘a1’ with actual type ‘a2’
‘a2’ is a rigid type variable bound by
the type signature for:
isPrimeHelper :: forall a2. Integral a2 => a2 -> Bool
at test.hs:5:29-68
‘a1’ is a rigid type variable bound by
the type signature for:
isPrime :: forall a1. Integral a1 => a1 -> Bool
at test.hs:3:15-48
• In the second argument of ‘mod’, namely ‘n’
In the first argument of ‘(/=)’, namely ‘number `mod` n’
In the expression: number `mod` n /= 0
• Relevant bindings include
n :: a2 (bound at test.hs:6:43)
isPrimeHelper :: a2 -> Bool (bound at test.hs:6:29)
number :: a1 (bound at test.hs:4:23)
isPrime :: a1 -> Bool (bound at test.hs:4:15)
|
6 | isPrimeHelper n = number `mod` n /= 0
|
findPrimes :: Integral a => [a] -> [a]
findPrimes numbers = [x | x <- numbers, isPrime x]
where isPrime :: Integral a => a -> Bool
isPrime number = all (isPrimeHelper) [2..number-1]
where isPrimeHelper :: Integral a => a -> Bool
isPrimeHelper n = number `mod` n /= 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment