Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Conditioned disjunction, Haskell

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading