(no subject)
Ashley Yakeley
ashley@semantic.org
Sun, 24 Feb 2002 23:02:14 -0800
At 2002-02-24 22:46, Tom Bevan wrote:
>I've come across this sort of data constructor below many times but I'm
>not really sure how to use it. Can someone please point me to the right
>section in the documentation?
http://haskell.org/onlinereport/decls.html#sect4.2.1
"Labelled Fields"
>In particular, I want to know how to create a calendar time and how to
>access the fields .
>
>Tom
>
>data CalendarTime = CalendarTime {
> ctYear :: Int,
> ctMonth :: Month,
> ctDay, ctHour, ctMin, ctSec :: Int,
> ctPicosec :: Integer,
> ctWDay :: Day,
> ctYDay :: Int,
> ctTZName :: String,
> ctTZ :: Int,
> ctIsDST :: Bool
> } deriving (Eq, Ord, Read, Show)
Basically it's equivalent to this:
data CalendarTime = CalendarTime Int Month Int Int Int Int Integer Day
Int String Int Bool deriving (Eq, Ord, Read, Show);
ctYear (CalendarTime x _ _ _ _ _ _ _ _ _ _ _) = x;
ctMonth (CalendarTime _ x _ _ _ _ _ _ _ _ _ _) = x;
ctDay (CalendarTime _ _ x _ _ _ _ _ _ _ _ _) = x;
etc.
...but you can also use the labelled fields to construct:
CalendarTime
{
ctYear = 2002,
ctMonth = 2,
...
}
--
Ashley Yakeley, Seattle WA