On 2/23/07, skaller <[EMAIL PROTECTED]> wrote:
> I'm hopefully off to a job interview soon for a SCADA
> application (industrial automation). C++/C# combo on Windows.
>

[...]

> I barely understand what a GADT is .. how would I
> explain how it helps a commercial client?
>

The key example for GADTs is :

data Term a where
   Lit  :: Int -> Term Int
   Inc  :: Term Int -> Term Int
   IsZ  :: Term Int -> Term Bool
   If   :: Term Bool -> Term a -> Term a -> Term a
   Pair :: Term a -> Term b -> Term (a,b)
   Fst  :: Term (a,b) -> Term a
   Snd  :: Term (a,b) -> Term b

eval :: Term a -> a
eval t =
 case t of
   Lit i -> i
   Inc t -> eval t + 1
   IsZ t -> eval t == 0
   If b t e -> if eval b then eval t else eval e
   Pair a b -> (eval a, eval b)
   Fst t -> fst (eval t)
   Snd t -> snd (eval t)

You certainly already seen it.
Now there is two key features about GADTs:

1/ You seen that in the type declaration one can choose the return
type of data constructors.
In OCaml for instance, by default when defining 'a term the return
type is always 'a term it cannot be refined for a given data
constructor.
Here one use the type variable of Term a to make sure that terms are
always well-typed and that eval will works without boxing values.

2/ To make it works one must extend the match construct to propagate
type information. In each branch of the case the precise type of `t'
is different for instance in the `Lit' case the type of `t' is Term
Int, and in the `Pair' case the type is Term (a,b).

Two useful papers:

- Towards efficient, typed LR parsers:
   http://cristal.inria.fr/~fpottier/publis/fpottier-regis-gianas-typed-lr.pdf

- Stratified type inference for generalized algebraic data types:
   http://cristal.inria.fr/~fpottier/publis/pottier-regis-gianas-popl06.pdf

Regards,

--
Nicolas Pouillard

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to