2
Ben kodu yazdı:Haskell Tipi sorunu
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE FlexibleInstances #-}
module MonoidApp where
class Monoid' a where
mempty' :: a
mappend' :: a -> a -> a
mconcat' :: [a] -> a
mconcat' = foldr mappend' mempty'
instance Monoid' Int where
mempty' :: Int a => a
mempty' = 0
mappend' :: Int a => a -> a -> a
mappend' a b = (+) a b
Ama yanılgıya çalıştırır:
‘Int’ is applied to too many type arguments
In the type signature for ‘mempty'’: mempty' :: Int a => a
In the instance declaration for ‘Monoid' Int’
Failed, modules loaded: none.
Herhangi bir fikir neden?
hata mesajı oldukça açıktır. Sanırım aslında 'mempty' demek istediniz :: Int; mappend ':: Int -> Int -> Int'. –
Eğer 'mempty' çizgilerini dışarda bırakırsanız? :: Int a => a 've 'mappend' :: Int a => a -> a -> a'? –
@JJHakala O zaman işlevini ('mappend '1 2') parametresiyle kullanamıyorum: _No örneği için' it'_ – barbara