[Haskell-cafe] Introspection
Sharadha Raghunathan
sweshar.sis at gmail.com
Fri Jul 22 16:49:49 CEST 2011
Thanks. Let me try this. I appreciate all the help. And how do I compute a LR parser graph using haskell?
Sent from my iPhone
On Jul 22, 2011, at 6:41 AM, Felipe Almeida Lessa <felipe.lessa at gmail.com> wrote:
> On Fri, Jul 22, 2011 at 10:31 AM, Stephen Tetley
> <stephen.tetley at gmail.com> wrote:
>> As Haskell is statically typed, if y.length < 100, y is still of type Big...
>
> You could achieve this kind of thing with smart constructors and
> GADTs. I don't know how useful it is, though =).
>
> data Sized t a where
> Small :: a -> Sized Small a
> Big :: a -> Sized Big a
>
> data Small -- empty
> data Big -- empty
>
> retrieve :: Sized t a -> a
> retrieve (Small a) = a
> retrieve (Big a) = a
>
> toSmall :: [a] -> Maybe (Sized Small [a])
> toSmall xs = if length xs < 100 then Just (Small xs) else Nothing
>
> toBig :: ... -- almost the same as toSmall
>
> toUnknown :: [a] -> (forall t. Sized t [a] -> r) -> r
> toUnknown xs f = if length xs < 100 then f (Small xs) else f (Big xs)
>
> --
> Felipe.
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list