
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:me@alexjacobson.com tel:917-770-6565 http://alexjacobson.com

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

"Arjan van IJzendoorn"
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

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"
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:me@alexjacobson.com tel:917-770-6565 http://alexjacobson.com
participants (4)
-
Arjan van IJzendoorn
-
Ketil Malde
-
S. Alexander Jacobson
-
Stefan Holdermans