pattern-matching extension?
Bernard James POPE
bjpop at cs.mu.OZ.AU
Sat Dec 6 17:15:28 EST 2003
Abe writes:
> The thought occurred to me that it is (intuitively) natural to do this via
> extending the pattern-matching facility to include types as well as
> literal values, i.e. something like:
>
> f :: a -> String
> f (a :: Int) = "got an int, incremented: "++(show (a+1))
> f (a :: Show q => q) = "got a showable: "++(show a)
> f _ = "got something else"
>
> This has a couple of nice features - it's a simple extension of the
> syntax, and acts as a sort of type-safe typecast. However, I have zero
> knowledge of how hard it would be to implement this, and there may be
> theoretical difficulties I haven't seen. Thoughts?
Certainly seems like a useful thing to be able to do.
Systems along the same lines have been discussed in the literature,
for example:
@article{MLdynamics,
author = {X. Leroy and M. Mauny},
title = {Dynamics in {ML}},
journal = {Journal of Functional Programming},
year = 1993,
volume = 3,
number = 4,
pages = {431--463}
}
@phdthesis{Dornan98,
author= {C. {Bentley Dornan}},
title= {Type-Secure Meta-Programming},
school= {Faculty of Engineering, University of Bristol},
year= {1998},
address= {Bristol, United Kingdom},
}
@inproceedings{Pil98,
author = {M. Pil},
editor = {K. Hammond and A. Davie and C. Clack},
title = {Dynamic Types and Type Dependent Functions},
booktitle = {Implementation of Functional Languages},
pages = {169--185},
year = {1998},
volume = {LNCS 1595},
}
Cheers,
Bernie.
More information about the Haskell
mailing list