class Greeting a where
name :: a -> String
hello :: a -> String
hello _ = "..."
bye :: a -> String
bye _ = "..."
instance Greeting Human where
name (Human n) = n
hello h = "Hi, I am " ++ name h ++ "."
bye _ = "See you again!"
というものを $ghciでコンパイルすると
[1 of 1] Compiling Main ( myfunctions.hs, interpreted )
myfunctions.hs:44:19: error:
Not in scope: type constructor or class ‘Human’
|
44 | instance Greeting Human where
| ^^^^^
myfunctions.hs:45:8: error: Not in scope: data constructor ‘Human’
|
45 | name (Human n) = n
| ^^^^^
Failed, no modules loaded.
というエラーが出て compileに失敗するのです
正直のところさっぱり分かりません この Monoidとか Monadとかを理解するには自分の能力が far awayと感じます
class Monoid a where
mempty:: a
mappend:: a -> a -> a
mconcat::[a] -> a
mconcat = foldr mappend mempty
instance Monoid [a] where
mempty = []
mappend = (++)