Re: [Haskell-cafe] ????Pattern match(es) are overlapped???

2004-03-22 Thread S. Alexander Jacobson
I actually ended up using a lookup list e.g.

   handlers=[(getMethod,doGet),(putMethod,doPut)]

which has the convenience of being able to put a
501 "Not Implemented" in an obvious place.

I'll post the code shortly.  My goal is to form
the core of a generically useful HTTP
haskell server library.

-Alex-


On Mon, 22 Mar 2004, Ketil Malde wrote:

> "Arjan van IJzendoorn" <[EMAIL PROTECTED]> writes:
>
> >>newtype Method = Method String
> >>getMethod = Method "GET"
> >>putMethod = Method "PUT"
> >>doMeth getMethod = ...
> >>doMeth putMethod = ...
>
> > You will have to write:
> >
> > doMeth (Method "GET") = ...
> > doMeth (Method "PUT") = ...
>
> Or (I assume, haven't tested) if you insist on renaming the methods:
>
>   doMeth m | m == getMethod = ...
>| m == putMethod = ...
>
> (or using a case statement, of course)
>
> -kzm
> --
> If I haven't seen further, it is by standing in the footprints of giants
>

_
S. Alexander Jacobson  mailto:[EMAIL PROTECTED]
tel:917-770-6565   http://alexjacobson.com
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


RE: [Haskell-cafe] ????Pattern match(es) are overlapped???

2004-03-22 Thread Stefan Holdermans
Hi,

> Or (I assume, haven't tested) if you insist on renaming the methods:
> 
>   doMeth m | m == getMethod = ...
>| m == putMethod = ... 

This, of course, assumes that you've derived (or declared) Method an
instance of Eq.

Regards,

Stefan


___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ????Pattern match(es) are overlapped???

2004-03-22 Thread Ketil Malde
"Arjan van IJzendoorn" <[EMAIL PROTECTED]> writes:

>>newtype Method = Method String
>>getMethod = Method "GET"
>>putMethod = Method "PUT"
>>doMeth getMethod = ...
>>doMeth putMethod = ...

> You will have to write:
> 
> doMeth (Method "GET") = ...
> doMeth (Method "PUT") = ...

Or (I assume, haven't tested) if you insist on renaming the methods:

  doMeth m | m == getMethod = ...
   | m == putMethod = ...

(or using a case statement, of course)

-kzm
-- 
If I haven't seen further, it is by standing in the footprints of giants
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ????Pattern match(es) are overlapped???

2004-03-22 Thread Arjan van IJzendoorn
>newtype Method = Method String
>getMethod = Method "GET"
>putMethod = Method "PUT"
>
>[...]
>
>doMeth getMethod = ...
>doMeth putMethod = ...

For Haskell the last two lines look both like pattern-matching on a variable
which always matches. You might as well have written:

doMeth x = ...
doMeth y = ...

There is no macro facility in Haskell so you cannot give patterns a name
like you do in line 2 and 3.
You will have to write:

doMeth (Method "GET") = ...
doMeth (Method "PUT") = ...

Good luck, Arjan

___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] ????Pattern match(es) are overlapped???

2004-03-22 Thread S. Alexander Jacobson
I am implementing HTTP and I have something like:

   newtype Method = Method String
   getMethod = Method "GET"
   putMethod = Method "PUT"

   [...]

   doMeth getMethod = ...
   doMeth putMethod = ...

GHC gives me a patter matches are overlapped
warning.

And when I run, I discover that pattern matching
is not actually happening.  getMethod is
always executed even though the method passed
is putMethod

What am I doing wrong?

-Alex-

_
S. Alexander Jacobson  mailto:[EMAIL PROTECTED]
tel:917-770-6565   http://alexjacobson.com
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe