Views in Haskell
John Meacham
john at repetae.net
Wed Jan 24 20:22:30 EST 2007
I am having a hard time figuring out what views gain you, if anything.
If you know from the start you want abstract deconstructors, then you
can do that now and it has never been an issue, just mechanical and
verbose:
> date Term = Ap Term Term | Let Id Term Term
>
> fromAp :: Term -> Maybe (Term,Term)
> fromAp (Ap a b) = Just (a,b)
> fromAp _ = Nothing
>
>
> foo t | Just (a,b) <- fromAp t = ...
now views give you some (perhaps) nicer syntax for matching these sort
of functions, but they don't make declaring them any less mechanical and
verbose, but more importantly, you still have to know a priori whether
you will need abstract deconstructors or not.
the issue that needs to be solved is letting you extend pattern matching
"after the fact", if you know you want abstract deconstructors from the
beginning, then views don't make much difference, if you don't and want
to seamlessly extend an existing type, then you are out of luck, views
or not.
John
--
John Meacham - ⑆repetae.net⑆john⑈
More information about the Haskell-prime
mailing list