Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Suppose you have:</p> <pre><code>myDate = Gtg 7 Jan 2013 myPerson = Person "Joe" "Bloe" myDate myEintrag = (myPerson, ???, ???) -- I don't know what Anschrift and SozNr look like </code></pre> <p>Here are some examples of how you access them:</p> <pre><code>putStrLn $ show (vorname myPerson) putStrLn $ show (nachname myPerson) let (a, _, _) = myEintrag putStrLn $ show (nachname a) let (Gtg d m y) = geburtstag a putStrLn $ show y </code></pre> <p>If you used named fields on <code>Geburtstag</code> and <code>Eintrag</code> as you did with <code>Person</code>, it might be more convenient (depending on your application). Otherwise, you have to pattern match on those fields, as I've done here.</p> <hr> <p>EDIT: You say you already have getPerson, which I assume looks something like this:</p> <pre><code>getPerson :: Eintrag -&gt; Person getPerson (p, _, _) = p </code></pre> <p>So in my example, <code>getPerson myEintrag</code> would return <code>myPerson</code>.</p> <p>You don't need to write a function to extract the geburtstag from a person; naming the field gives you that function automatically. So <code>geburtstag (getPerson myEintrag)</code> would extract the geburtstag from a Person. From there, you could define functions such as:</p> <pre><code>getDay :: Geburtstag -&gt; Int getDay (Gtg d _ _) = d </code></pre> <p>And then <code>getDay (geburtstag (getPerson myEintrag))</code>, or equivalently, <code>getDay . geburtstag . getPerson $ myEintrag</code> would get you the day from the Eintrag.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload