diff --git a/sample-programs/basic-1 b/sample-programs/basic-1 index 107fb5f..7a458eb 100644 --- a/sample-programs/basic-1 +++ b/sample-programs/basic-1 @@ -19,16 +19,32 @@ -- main = apply (krimp) 2 3; -- answer: 5 -fibbonaci : Int -> Int; -fibbonaci x = case x of { - 0 => 0, - 1 => 1, - -- abusing overflows to represent negatives like a boss - _ => (fibbonaci (x - 2)) - + (fibbonaci (x - 1)) +-- fibbonaci : Int -> Int; +-- fibbonaci x = case x of { +-- 0 => 0, +-- 1 => 1, +-- -- abusing overflows to represent negatives like a boss +-- _ => (fibbonaci (x - 2)) +-- + (fibbonaci (x - 1)) +-- } : Int; +-- main : Int; +-- main = fibbonaci 10; +-- answer: 55 + +succ : Int -> Int; +succ x = x - 1; + +isZero : Int -> Int; +isZero x = case x of { + 0 => 1, + _ => 0 } : Int; +minimization : (Int -> Int) -> Int -> Int; +minimization p x = case p x of { + 1 => 0, + _ => minimization p (succ x) +} : Int; main : Int; -main = fibbonaci 10; --- answer: 55 +main = minimization isZero 10; \ No newline at end of file diff --git a/src/Main.hs b/src/Main.hs index 8309349..29b7158 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -14,7 +14,8 @@ import Data.List.Extra (isSuffixOf) import LambdaLifter (lambdaLift) import Renamer (rename) import System.Directory (createDirectory, doesPathExist, - getDirectoryContents, + getDirectoryContents, removeDirectory, + removeDirectoryRecursive, setCurrentDirectory) import System.Environment (getArgs) import System.Exit (exitFailure, exitSuccess) @@ -54,7 +55,8 @@ main' debug s = do --putStrLn compiled check <- doesPathExist "output" - unless check (createDirectory "output") + when check (removeDirectoryRecursive "output") + createDirectory "output" writeFile "output/llvm.ll" compiled if debug then debugDotViz else putStrLn compiled