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

Unknown error in Haskell that prevents a function from running

I am extremely new to haskell and have recieved a task to create a list of atributes and then create a function that outputs a list of atributes that apply to the input but for some reason it only gives me an error. Below is a snippet of the code and the error

properties :: [Predicate Thing]
properties = [isBlue, isThick, isThin, isOrange, isDisc, isSquare, isBig, isSmall]

propertiesOf :: Thing -> [Predicate Thing] 
propertiesOf x = [props | props <- properties, props x == True]

and the error:

<interactive>:8:1: error: [GHC-39999] * No instance for Show (Thing -> Bool)'arising from a use of print' (maybe you haven't applied a function to enough arguments?) * In a stmt of an interactive GHCi command: print it

I expected to input one of the "things" that is orange, a disc, big, and thick and recieve the output:

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

>[isBig, isDisc, isOrange, isThick]

I am unsure why my function as listed above doesn’t work.

>Solution :

isBlue et al. are not values to print; they are just variable names, and those variables have functions as their values. You cannot print a function.

Predicate here appears to just be a type synonym, defined as something like

type Predicate a = a -> Bool

since the error message refers to Thing -> Bool rather than Predicate Bool.

If Predicate were a new type, it could have a show instance, but it couldn’t simply show the function it wraps (and it can’t print the name of the variable bound to the value).

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