[Haskell-cafe] Re: Polymorphic (typeclass) values in a list?

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Sun Oct 21 11:11:17 EDT 2007


On Oct 21, 2007, at 6:41 , Peter Hercek wrote:

> Brandon S. Allbery KF8NH wrote:
>> On Oct 19, 2007, at 12:11 , Sebastian Sylvan wrote:
>>> On 19/10/2007, Kalman Noel <kalman.noel at bluebottle.com> wrote:
>>>>
>>>>    data ExistsNumber = forall a. Num a => Number a
>>>
>>> I'm without a Haskell compiler, but shouldn't that be "exists a."?
>> The problem is that "exists" is not valid in either Haskell 98 or  
>> any current extension, whereas "forall" is a very common  
>> extension.  But you can simulate "exists" via "forall", which is  
>> the thrust of these approaches.
>
> When 'exists' is not a keyword, why 'forall' is needed at all?

NB.  Haskell98 doesn't have forall.  All type variables are  
implicitly scoped to the entire type (e.g. foo :: (a -> b) -> a -> b  
is actually foo :: forall a b. (a -> b) -> a -> b).

The point of the forall keyword is that it can be scoped.  Compare  
runState to runST:  ST carries around a bracketed forall on the state  
expression (forall s. ST s a), preventing it from being viewed or  
modified (or initialized!) outside the scope established by runST,  
whereas you can carry around a State (State s a) and thread the state  
s through an expression "by hand" via evalState / execState (or  
pattern matching on the State value, which is what those translate to  
after a pass through runState).

Given scoped forall, you can simulate exists by using something very  
like (identical to, via Curry-Howard?) de Morgan's Rule.

-- 
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH




More information about the Haskell-Cafe mailing list