Skip to content

Commit

Permalink
Restrict to single data-contructor records for context
Browse files Browse the repository at this point in the history
  • Loading branch information
singpolyma committed Aug 20, 2012
1 parent 7a90b22 commit 8f09fdd
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions ParseRecords.hs
Expand Up @@ -49,12 +49,14 @@ extractFromField types (name, t) =

extractFromRecordConstructor :: [(String, HsType)] -> HsConDecl -> [Field]
extractFromRecordConstructor types (HsRecDecl _ _ fields) = map (extractFromField types) fields
extractFromRecordConstructor _ _ = []
extractFromRecordConstructor _ _ = error "Only single data-constructor records may be used as context"

extractFromDataDecl :: [(String, HsType)] -> HsDecl -> (String, Record)
extractFromDataDecl types (HsDataDecl _ _ typeName _ constructors _) =
(hsNameToString typeName, concatMap (extractFromRecordConstructor types) constructors)
extractFromDataDecl _ _ = error "Programmer error, only call extractFromDataDecl with TypeDecl"
extractFromDataDecl types (HsDataDecl _ _ typeName _ [constructor] _) =
(hsNameToString typeName, extractFromRecordConstructor types constructor)
extractFromDataDecl _ (HsDataDecl _ _ typeName _ _ _) =
(hsNameToString typeName, error "Only single data-constructor records may be used as context")
extractFromDataDecl _ _ = error "Programmer error, only call extractFromDataDecl with DataDecl"

extractFromTypeDecl :: HsDecl -> (String, HsType)
extractFromTypeDecl (HsTypeDecl _ name _ t) = (hsNameToString name, t)
Expand Down

0 comments on commit 8f09fdd

Please sign in to comment.