ある数がその要素に含まれているかどうかを判定する関数mを作成したいのですが、実行は出来るものの、実行したときに計算してくれません。
どこが間違っていますでしょうか。回答よろしくお願いします。
作成したプログラム:
m([],x)=False
m(as,x)=if memberOf(as,x) then True else False
memberOf(x,[])=False
memberOf(x,a:as)=if x==a then True else memberOf(x,as)
期待している実行結果:
*Main> m([100,54,89,27,76,45], 76)
True
*Main> m([100,54,89,27,76,45], 88)
False
実際の実行結果:
<interactive>:13:1: error:
• Ambiguous type variable ‘t0’ arising from a use of ‘m’
prevents the constraint ‘(Eq t0)’ from being solved.
Probable fix: use a type annotation to specify what ‘t0’ should be.
These potential instances exist:
instance Eq Ordering -- Defined in ‘GHC.Classes’
instance Eq Integer
-- Defined in ‘integer-gmp-1.0.0.1:GHC.Integer.Type’
instance Eq a => Eq (Maybe a) -- Defined in ‘GHC.Base’
...plus 22 others
...plus 8 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the expression: m ([1, 2, 3, 4, ....], 1)
In an equation for ‘it’: it = m ([1, 2, 3, ....], 1)
<interactive>:13:4: error:
• Ambiguous type variable ‘t0’ arising from the literal ‘1’
prevents the constraint ‘(Num t0)’ from being solved.
Probable fix: use a type annotation to specify what ‘t0’ should be.
These potential instances exist:
instance Num Integer -- Defined in ‘GHC.Num’
instance Num Double -- Defined in ‘GHC.Float’
instance Num Float -- Defined in ‘GHC.Float’
...plus two others
(use -fprint-potential-instances to see them all)
• In the expression: 1
In the expression: [1, 2, 3, 4, ....]
In the first argument of ‘m’, namely ‘([1, 2, 3, 4, ....], 1)’
<interactive>:13:15: error:
• No instance for (Num [[t0]]) arising from the literal ‘1’
• In the expression: 1
In the first argument of ‘m’, namely ‘([1, 2, 3, 4, ....], 1)’
In the expression: m ([1, 2, 3, 4, ....], 1)