[Haskell] Views in Haskell

Brian Hulley brianh at metamilk.com
Wed Jan 24 07:22:01 EST 2007


On Wednesday, January 24, 2007 10:02 AM, Dinko Tenev wrote:
> On 1/24/07, Brian Hulley <brianh at metamilk.com> wrote:
>> A possible syntax could represent the
>> value being matched explicitly, say using ? to represent the value 
>> currently
>> being matched, then the pattern could be written as an equation:
>>
>>    f (prodSize ? = Small) = ...
>>    f (prodSize ? = Medium) = ...
>>    f (prodSize ? = Big) = ...

> ...or maybe (Small = prodSize ?), etc., to be consistent with let 
> bindings?

I like it!
Just to fix a minor error in one of my previous examples, and to show it in 
let-compatible form:

    -- "n+3" pattern matching against 2nd element
    j (_ : (n = ? - 3) : _ = toList ?) = ...

Also, perhaps the "binding" could be optional for "True = ", so that:

    test (True = isAlpha ?) = ...

could just be written as:

    test (isAlpha ?) = ...

(The presence of '?' in the pattern is enough to specify that it's an 
"active" pattern)

Here is another example, in current syntax and in "new" syntax:

    old (n + 3) | 0 < n = ...    -- using idiosyncratic n+k pattern

    new (n = ? - 3) | 0 < n = ...    -- rational reconstruction
or
    new (n @ (0 < ?) = ? - 3) = ... -- moving guard into pattern

Brian.
-- 
http://www.metamilk.com




More information about the Haskell-prime mailing list