haskellsieve-of-eratosthenes

or takes two values arguments haskell


I am a beginner in haskell and I tried to define a simple function for Sieve of Eratosthenes but it says error:

    • Couldn't match expected type ‘Bool -> Bool’
                  with actual type ‘Bool’
    • The function ‘or’ is applied to two value arguments,
        but its type ‘t Bool -> Bool’ has only one
      In the expression: or (mod n x) (divl l x)
      In an equation for ‘divl’: divl (n : l) x = or (mod n x) (divl l x)
   |
13 | divl (n:l) x = or (mod n x) (divl l x)
erat l [] = l
erat l (x:t) = if divl l x then erat l t else erat (x:t) l

divl (n:l) x = or (mod n x) (divl l x)
divl [] x = True

I tried to write that as an operator with "`" but nothing worked


Solution

  • or is not the boolean OR operator; that's (||). or takes a list (well, Foldable) of Boolean values and returns True if at least one value is True.

    > or []
    False
    > or [True, False]
    True
    

    (Note that or [] is defined to be False to preserve the identity or xs || or ys == or (xs ++ ys). As a concrete example, or [] || or [False] == or [False].)