functionhaskell

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:

>[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).