Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

X {..} <- getYesod notation

Tags:

haskell

yesod

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

like image 845
Richard Cook Avatar asked Oct 10 '15 13:10

Richard Cook


1 Answers

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
like image 167
Lee Avatar answered Nov 09 '22 06:11

Lee