Skip to main content

Note for LI Functional Programming - Week 2

Handout

type classes and Instances

练习

Prelude> False == 'c'
<interactive>:1:10: error:
• Couldn't match expected type 'Bool' with actual type 'Char'
• In the second argument of '(==)', namely ''c''
In the expression: False == 'c'
In an equation for 'it': it = False == 'c'
Prelude> False == True
False
Prelude> False == not

<interactive>:3:10: error:
• Couldn't match expected type 'Bool'
with actual type 'Bool -> Bool'
• Probable cause: 'not' is applied to too few arguments
In the second argument of '(==)', namely 'not'
In the expression: False == not
In an equation for 'it': it = False == not
Prelude> False == not True
True
Prelude> not == id

<interactive>:5:1: error:
• No instance for (Eq (Bool -> Bool)) arising from a use of '=='
(maybe you haven't applied a function to enough arguments?)
• In the expression: not == id
In an equation for 'it': it = not == id
Prelude> [not] == [ (id :: Bool -> Bool) ]

<interactive>:6:1: error:
• No instance for (Eq (Bool -> Bool)) arising from a use of '=='
(maybe you haven't applied a function to enough arguments?)
• In the expression: [not] == [(id :: Bool -> Bool)]
In an equation for 'it': it = [not] == [(id :: Bool -> Bool)]