git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
More tests, handle Void types
commitb4e5bf2b336aa400b50cec3b6c8274d4bc8e0297 authorPhil Freeman <paf31@cantab.net> dateSat 6 Feb 2016, 16:50 (11 years ago) parent8838396
2 files changed+17−2
examples/passing/Deriving.purs+6 src/Language/PureScript/Sugar/TypeClasses/Deriving.hs+11−2
examples/passing/Deriving.purs+6
@@ -3,6 +3,12 @@ module Main where
33import Prelude
44import Test.Assert
55
6+data V
7+
8+derive instance eqV :: Eq V
9+
10+derive instance ordV :: Ord V
11+
612data X = X Int | Y String
713
814derive instance eqX :: Eq X
src/Language/PureScript/Sugar/TypeClasses/Deriving.hs+11−2
@@ -251,7 +251,9 @@ deriveEq mn ds tyConNm = do
251251 preludeEq = App . App (Var (Qualified (Just (ModuleName [ProperName C.prelude])) (Ident C.eq)))
252252
253253 addCatch :: [CaseAlternative] -> [CaseAlternative]
254− addCatch = (++ [catchAll])
254+ addCatch xs
255+ | length xs /= 1 = xs ++ [catchAll]
256+ | otherwise = xs -- Avoid redundant case
255257 where
256258 catchAll = CaseAlternative [NullBinder, NullBinder] (Right (BooleanLiteral False))
257259
@@ -290,7 +292,7 @@ deriveOrd mn ds tyConNm = do
290292 mkCompareFunction (DataDeclaration _ _ _ args) = do
291293 x <- freshIdent "x"
292294 y <- freshIdent "y"
293− lamCase2 x y <$> (concat <$> mapM mkCtorClauses (splitLast args))
295+ lamCase2 x y <$> (addCatch . concat <$> mapM mkCtorClauses (splitLast args))
294296 mkCompareFunction (PositionedDeclaration _ _ d) = mkCompareFunction d
295297 mkCompareFunction _ = internalError "mkCompareFunction: expected DataDeclaration"
296298
@@ -299,6 +301,13 @@ deriveOrd mn ds tyConNm = do
299301 splitLast [x] = [(x, True)]
300302 splitLast (x : xs) = (x, False) : splitLast xs
301303
304+ addCatch :: [CaseAlternative] -> [CaseAlternative]
305+ addCatch xs
306+ | null xs = [catchAll] -- No type constructors
307+ | otherwise = xs
308+ where
309+ catchAll = CaseAlternative [NullBinder, NullBinder] (Right (preludeCtor "EQ"))
310+
302311 preludeCtor :: String -> Expr
303312 preludeCtor = Constructor . Qualified (Just (ModuleName [ProperName C.prelude])) . ProperName
304313