I declared a recursive data type with the following structure:
data Path = GET | POST | Slash Path String
I would really like to rename this last constructor of values ββto / so that I can infinit it in nice expressions, like GET /"controller"/"action" . However, if I try to do this:
import Prelude hiding ((/)) infixr 5 / data Path = GET | POST | Path / String
... then I get the following:
Path.hs:4:30: parse error on input `/'
The same three lines compile just fine if I replace / with :/ or any other special character sequence starting with :
So, is there any way to name your constructor for the values ββof / ? I know that I can just call it Slash and then declare a separate function:
(/) :: Path -> String -> Path (/) = Slash
... but this will not give me pattern matching, as in:
request :: Path -> String request path = case path of GET /"hello" -> "Hello!" GET /"goodbye" -> "Goodbye!"
syntax haskell
Tom
source share