8

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 {..}.

Richard Cook
  • 32,523
  • 5
  • 46
  • 71

1 Answers1

10

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
Lee
  • 142,018
  • 20
  • 234
  • 287
  • 1
    You can link directly to a section in the GHC documentation. For example: https://downloads.haskell.org/~ghc/7.10.2/docs/html/users_guide/syntax-extns.html#record-wildcards – Taylor Fausak Oct 10 '15 at 13:44