I'm seeing this kind of notation all over sample code for Yesod web applications and have no idea what it means:
getHomeR :: Handler Html
getHomeR = do
App {..} <- getYesod
What does this syntax mean?
I'm also seeing the following, I assume related, notation:
getHomeR :: Handler Html
getHomeR = do
App x <- getYesod
i.e. Some identifier x
in place of the cryptic {..}
.
These are called record wildcards - given a record definition (App
in this case), the pattern App { .. }
brings all the field names into scope. For example given the following record definition
{-# LANGUAGE RecordWildCards #-}
data Test = Test { a :: Int, b :: Int }
you can match on it in a pattern, bringing the a
and b
fields into scope e.g.
sumTest :: Test -> Int
sumTest Test {..} = a + b
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With