Ho un tipo (chiamiamolo A) e voglio fare un typeclass delle funzioni di tipo A -> A, A -> A -> A, A -> A -> A -> ecc ... Questo non funziona:Haskell - Tutte le funzioni del modulo 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)
ottengo il seguente messaggio di errore:
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)
Tutte le idee? Grazie mille per qualsiasi consiglio.
Sono sicuro al 90% che è perché 'takeA' è implicitamente esistenzialmente quantificata. –