Merge pull request #7 from msydneyslaga/dev
idCase test
This commit was merged in pull request #7.
This commit is contained in:
@@ -8,6 +8,7 @@ module Core.Examples
|
|||||||
( fac3
|
( fac3
|
||||||
, sumList
|
, sumList
|
||||||
, constDivZero
|
, constDivZero
|
||||||
|
, idCase
|
||||||
) where
|
) where
|
||||||
----------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------
|
||||||
import Core.Syntax
|
import Core.Syntax
|
||||||
@@ -181,6 +182,15 @@ constDivZero = [coreProg|
|
|||||||
main = k 3 ((/#) 1 0);
|
main = k 3 ((/#) 1 0);
|
||||||
|]
|
|]
|
||||||
|
|
||||||
|
idCase :: Program'
|
||||||
|
idCase = [coreProg|
|
||||||
|
id x = x;
|
||||||
|
|
||||||
|
main = id (case Pack{1 0} of
|
||||||
|
{ 1 -> (+#) 2 3
|
||||||
|
})
|
||||||
|
|]
|
||||||
|
|
||||||
corePrelude :: Module Name
|
corePrelude :: Module Name
|
||||||
corePrelude = Module (Just ("Prelude", [])) $
|
corePrelude = Module (Just ("Prelude", [])) $
|
||||||
-- non-primitive defs
|
-- non-primitive defs
|
||||||
|
|||||||
@@ -46,8 +46,7 @@ type Floater = StateT [Name] (Writer [ScDef'])
|
|||||||
runFloater :: Floater a -> (a, [ScDef'])
|
runFloater :: Floater a -> (a, [ScDef'])
|
||||||
runFloater = flip evalStateT ns >>> runWriter
|
runFloater = flip evalStateT ns >>> runWriter
|
||||||
where
|
where
|
||||||
-- TODO: safer, uncapturable names
|
ns = [ "$nonstrict_case_" ++ showHex n "" | n <- [0..] ]
|
||||||
ns = [ "nonstrict_case_" ++ showHex n "" | n <- [0..] ]
|
|
||||||
|
|
||||||
-- TODO: formally define a "strict context" and reference that here
|
-- TODO: formally define a "strict context" and reference that here
|
||||||
-- the returned ScDefs are guaranteed to be free of non-strict cases.
|
-- the returned ScDefs are guaranteed to be free of non-strict cases.
|
||||||
|
|||||||
@@ -36,3 +36,6 @@ spec = do
|
|||||||
it "k 3 ((/#) 1 0)" $ do
|
it "k 3 ((/#) 1 0)" $ do
|
||||||
resultOf Ex.constDivZero `shouldBe` Just (NNum 3)
|
resultOf Ex.constDivZero `shouldBe` Just (NNum 3)
|
||||||
|
|
||||||
|
it "id (case ... of { ... })" $ do
|
||||||
|
resultOf Ex.idCase `shouldBe` Just (NNum 5)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user