From 0a7d5fa12467b0823bee3d883f9cd5d5d6f99887 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 4 Aug 2016 19:17:58 -0400 Subject: [PATCH] Add a function to retrieve the head element of a non-empty record. --- src/Data/Record.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Data/Record.hs b/src/Data/Record.hs index 5a2665428..12f3d37bd 100644 --- a/src/Data/Record.hs +++ b/src/Data/Record.hs @@ -2,6 +2,7 @@ module Data.Record ( Record(..) , (.:) +, rhead , HasField(..) , maybeGetField , updateField @@ -25,6 +26,11 @@ infixr 0 .: (.:) :: Typeable h => h -> Record t -> Record (h ': t) (.:) = RCons +-- | Get the first element of a non-empty record. +rhead :: Record (head ': tail) -> head +rhead (RCons head _) = head + + -- | Return 'Just' a 'field', if it exists in a record. Otherwise, return 'Nothing'. maybeGetField :: Typeable field => Record fields -> Maybe field maybeGetField (RCons h t) = cast h <|> maybeGetField t