D
D
Drovosek012018-04-06 21:46:54
Haskell
Drovosek01, 2018-04-06 21:46:54

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

Actually, what kind of operator is this at the end of the code, and why is it needed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Moseychuk, 2018-04-06
@Drovosek01

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 question

Ask a Question

731 491 924 answers to any question