[Haskell] Re: Context of a pattern variable

Daniel Yokomizo daniel_yokomiso at yahoo.com.br
Wed Jan 12 06:00:56 EST 2005


"Tomasz Zielonka" <tomasz.zielonka at gmail.com> escreveu na mensagem
news:20050111221204.GA15394 at students.mimuw.edu.pl...
[snip]

> BTW, I already see some problems with this syntax. For example, this code
>
>   case t of
>       (x, y, (a, ctx @> Just z)) -> ctx z
>
> wouldn't be equivalent to this one
>
>   case t of
>       (x, y, v) ->
>           case v of
>               ctx @> (a, Just z) -> ctx z


I think it would work better if the context was always bound to the whole
pattern, using '_' patterns to define which parts of the pattern would be
copied and naming only the parts which are going to be changed:

   case t of
       ctx @> (_, _, v) ->
           case v of
               (a, Just z) -> ctx (a, z)

or

   case t of
       ctx @> (_, _, (_, Just z)) -> ctx z

This don't have the ambiguity and the need to keep track wether the context
is declared inside a pattern match or not. Also it could be used to more
complex changes:

   case t of
       ctx @> (x, _, _, _, _, c) -> ctx (x+1) (c+2)

> I would love to hear you opinions. Maybe you can think of some really
> convincing (or unconvincing) code examples?
>
> Best regards,
> Tomasz

Best regards,
Daniel Yokomizo.

"You may want Star Wars compilers, but I'm no Luke Skywalker."
 - Cyril Adrian


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.832 / Virus Database: 566 - Release Date: 10/1/2005




More information about the Haskell mailing list