Reputation:
when trying to define a function that would remove the largest subset of set m that is also a subset of set a from set a, I encountered the following error:
filename.hs:7:33:parse error (possibly incorrect indentation)
for the following code:
exclude :: Integral t => [t] -> [t] -> [t]
a `exclude` m
| m == [] = a
| a == (b ++ c) = b
| otherwise = []
where b /= []
where c = [z | z <- m]
how do I implement multiple conditions/definitions (using where or otherwise), or correct the function to properly work in a different way?
Upvotes: 1
Views: 3639
Reputation: 1
In fact,there is a function in Data.List and Data.Set called '\'. I'll show '\' function of Data.List .
import Data.List
exclude :: Integral t => [t] -> [t] -> [t]
a `exclude` m = a\\m
Upvotes: 0
Reputation: 99
Saying "the largest subset of set m
that is also a subset of set a
"
is the same as saying "all elements of m
that are also elements of a
".
Then the solution to your problem is stated simply as:
exclude a = filter (`notElem` a)
which when applied to m
will give you a subset of m
modulo any elements
that are also members of a
. That is, it will "remove the largest subset of
m
that is also a subset of a
".
Upvotes: 4
Reputation: 183878
One part of your question is easily answerable. You can have multiple definitions in one where
clause, as in
foo n
| even r = bar
| s < 12 = baz
| otherwise = quux
where
r = n `mod` 1357
h = a + b
where
(a,b) = r `divMod` 53 -- nested where-clause
s = r - 3*h
and you can have nested where
-clauses. But in a where
-clause, you can only have definitions. Conditions would go into the guards (or if then else
expressions on the right hand side) and can be combined with the boolean operators, (&&)
, (||)
, not
...
As for your code, so far I haven't figured out what you intended it to do.
Upvotes: 5