Tôi có một loại (gọi nó là A) và tôi muốn tạo một kiểu chữ của các hàm kiểu A -> A, A -> A -> A, A -> A -> A -> ... vv Điều này không làm việc:Haskell - Tất cả các chức năng của mẫu A -> A -> ... -> A
{-# LANGUAGE FlexibleInstances #-}
data A = A
class AsToA a where
takeA :: AsToA b => a -> A -> Either A b
instance AsToA (A -> A) where
takeA f a = Left (f a)
instance AsToA b => AsToA (A -> b) where
takeA f a = Right (f a)
tôi nhận được thông báo lỗi sau:
AsToA.hs:12:22:
Couldn't match expected type ‘b1’ with actual type ‘b’
‘b’ is a rigid type variable bound by
the instance declaration at AsToA.hs:11:10
‘b1’ is a rigid type variable bound by
the type signature for
takeA :: AsToA b1 => (A -> b) -> A -> Either A b1
at AsToA.hs:12:3
Relevant bindings include
f :: A -> b (bound at AsToA.hs:12:9)
takeA :: (A -> b) -> A -> Either A b1 (bound at AsToA.hs:12:3)
In the first argument of ‘Right’, namely ‘(f a)’
In the expression: Right (f a)
Bất kỳ ý tưởng? Cảm ơn rất nhiều vì lời khuyên nào.
Tôi chắc chắn 90% đó là vì 'takeA' được định lượng tiềm ẩn hoàn toàn. –