Write a function that takes as input a list of Boolean values, the number of elements in which is a multiple of three, and returns a value that is obtained by sequentially applying the operation "conditional disjunction" to the k-th triple of list elements (the k-th triple is a triple of elements with numbers k, k+1 and k+2, k = 1,3,…,n-2). The result of applying the operation to the k-th pair of elements becomes the (k+2)th element of the intermediate list. Give three examples of using the function;
I’ve tried this code,but it doesn’t works
calc::[Bool]->Bool
calc [] = False
calc (p:[]) = False
calc (p:q:[]) = False
calc (p:q:r:[]) = ((not q||p)&&(q||r))
calc (p:q:r:xs) = calc(((not q||p)&&(q||r)):r:xs)
Compiller says
21.hs:3:19: parse error on input ‘=’
>Solution :
Your indentation is wrong – you’ve got separate function implementations for your patterns, so each of them should start on column 0:
calc::[Bool]->Bool
calc [] = False
calc (p:[]) = False
calc (p:q:[]) = False
calc (p:q:r:[]) = ((not q||p)&&(q||r))
calc (p:q:r:xs) = calc(((not q||p)&&(q||r)):r:xs)
See Learn you a Haskell: Syntax in functions