Answer the question
In order to leave comments, you need to log in
What does the as operator mean in hasekll?
Just started learning this AP. I'm reading a tutorial: anton-k.github.io/ru-haskell-book/book/2.html
There is such a code. As I understand it, "as" is not just a variable name, but some kind of keyword, because in the textbook, it is not highlighted like a regular variable.
instance Show Time where
show (Time h m s) = show h ++ ":" ++ show m ++ ":" ++ show s
instance Show Hour where
show (Hour h) = addZero (show h)
instance Show Minute where
show (Minute m) = addZero (show m)
instance Show Second where
show (Second s) = addZero (show s)
addZero :: String -> String
addZero (a:[]) = '0' : a : []
addZero as = as
Answer the question
In order to leave comments, you need to log in
It's not an operator, but a variable name. If the first match did not work (where there is 0 at the beginning of the string), then the function will return the string unchanged.
You can replace 'as' with any other identifier.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question