Permalink
Browse files

Restrict to single data-contructor records for context

  • Loading branch information...
1 parent 7a90b22 commit 8f09fdd1df8d8424d78d3bfea1f936928bb50395 @singpolyma committed Aug 20, 2012
Showing with 6 additions and 4 deletions.
  1. +6 −4 ParseRecords.hs
View
@@ -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)

0 comments on commit 8f09fdd

Please sign in to comment.