Quello che voglio è quello di scrivere qualcosa del genere:Control.Arrow: Perché "let (a, b) = (first, second)" non riesce?
let (a,b) = if *condition* then (first, second) else (second, first)
ho scoperto che non posso scrivere anche questo:
let (a,b) = (first,second)
Non riesce con un errore:
<interactive>:7:5:
Could not deduce (Arrow a0)
from the context (Arrow a)
bound by the inferred type for `a':
Arrow a => a b c -> a (b, d) (c, d)
at <interactive>:7:5-26
The type variable `a0' is ambiguous
When checking that `a' has the inferred type
a :: forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
Probable cause: the inferred type is ambiguous
<interactive>:7:5:
Could not deduce (Arrow a0)
from the context (Arrow a)
bound by the inferred type for `b':
Arrow a => a b c -> a (d, b) (d, c)
at <interactive>:7:5-26
The type variable `a0' is ambiguous
When checking that `b' has the inferred type
b :: forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
Probable cause: the inferred type is ambiguous
Simon Peyton-Jones ha una grande e-mail ad una delle mailing list (che ora sto avendo problemi a trovare), che discute le sottigliezze di attacchi modello typechecking come Questo. È così sottile, infatti, che il rapporto Haskell98 ha trascurato completamente la questione, e il comitato ha dedicato un po 'di tempo a riflettere su come dovrebbe essere fatto il typechecking per i binding di pattern prima di scrivere il report di Haskell 2010. Vorrei scrivere una risposta, tranne che non mi fido di me stesso per ottenere le sottigliezze giuste senza l'e-mail di SPJ di fronte a me ... –
Ad una ipotesi, il problema qui è che il lato destro del bind ottiene il tipo inferito 'forall a1 a2. (Freccia a1, Freccia a2) => (a1 ..., a2 ...) 'in contrapposizione a' (forall a1. Arrow a1 => ..., forall a2. Arrow a2 => ...) ', così il forall viene spostato * fuori * dalla tupla, e uno dei valori nella coppia non è completamente polimorfico. –