unsafe parsing

Derek Elkins ddarius@hotpop.com
Wed, 30 Apr 2003 09:47:06 -0400


On Wed, 30 Apr 2003 15:29:04 +0800
"Kenny Lu Zhuo Ming" <haskellmail@yahoo.com.sg> wrote:

> Hi all,
> 
> I am currently write a program to type a dynamic string consist of 'A'
> or 'B'
> 
> for short, it works in this manner: 
> for 'A', it returns A :: A
> for 'B', it returns B :: B
> for "A", it returns Cons A Nil :: Cons A Nil
> for "AB", it returns Cons A (Cons B Nil) :: Cons A (Cons B Nil)
> ...
> 
> The problem is I have to specifically annotate the output type, which
> is unaffordable, because I might have arbitrary-long string, and I
> have infinitely many possible singleton types. It seems it is
> impossible to do it in a type-safe way. Anyone of you have any idea to
> walk around that?
> 
> 
> 
> Regards,
> Kenny

Is there any reason [Either A B] couldn't be used?  Otherwise, you may
want to look at the thread "polymorphic stanamically typed balanced
trees" on this list (or haskell-cafe), and/or SimulatingDependentTypes
on the Haskell Wiki (it's linked from haskell.org). 
SimulatingDependentTypes also has a link to the aforementioned thread.