From 4a1ca3d68e1fa26524d9cac3f2a9f554f55d6cd1 Mon Sep 17 00:00:00 2001 From: saundersp Date: Thu, 5 Dec 2024 12:43:06 +0100 Subject: [PATCH] Changed repository to a cabal structure --- .gitignore | 5 +---- Makefile | 15 --------------- Main.hs => app/Main.hs | 19 ++++++++++--------- Math.hs => app/Math.hs | 0 Primes.hs => app/Primes.hs | 10 +++++----- Problems.hs => app/Problems.hs | 0 haskell-playground.cabal | 16 ++++++++++++++++ 7 files changed, 32 insertions(+), 33 deletions(-) delete mode 100644 Makefile rename Main.hs => app/Main.hs (93%) rename Math.hs => app/Math.hs (100%) rename Primes.hs => app/Primes.hs (56%) rename Problems.hs => app/Problems.hs (100%) create mode 100644 haskell-playground.cabal diff --git a/.gitignore b/.gitignore index 539fcfd..48a004c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1 @@ -*.hi -*.o -Main -Problems +dist-newstyle diff --git a/Makefile b/Makefile deleted file mode 100644 index 2210eda..0000000 --- a/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -.PHONY: all Main debug start clean - -all: Main - -Main: Main.hs - @ghc -Wno-tabs Main.hs - -start: Main - @./Main - -debug: Main.hs - @ghc -Wno-tabs -keep-hc-files -keep-tmp-files $^ - -clean: - @rm *.hi Main *.o || true diff --git a/Main.hs b/app/Main.hs similarity index 93% rename from Main.hs rename to app/Main.hs index 8386199..4c2d55d 100644 --- a/Main.hs +++ b/app/Main.hs @@ -1,7 +1,8 @@ import Problems ( myLast, lastTwo, kth, myLength, rev, isPalindrome, flatten, NestedList(..), compress, pack, encode ) --import Primes ( aspGetNextPrime, aspIsPrime, aspPrimes ) +import Primes ( aspGetNextPrime, aspIsPrime ) import Data.Numbers.Primes ( isPrime, primes, primeFactors ) -import Math ( mandlebrot ) +--import Math ( mandlebrot ) -- Unit testing main :: IO() @@ -9,7 +10,7 @@ main = do testMisc testProblems testPrimes - mandlebrot + --mandlebrot testMisc :: IO() testMisc = do @@ -37,7 +38,7 @@ testMisc = do putStrLn ("FizzBuzz 50 " ++ show (fizzBuzz [0..50])) putStrLn ("Fionacci 10 " ++ show (fibonacci 10)) - putStrLn ("FionacciList 10 " ++ show (fibonnaciSequence 10)) + putStrLn ("FionacciList 10 " ++ show (fibonaciSequence 10)) testProblems:: IO() testProblems = do @@ -137,14 +138,14 @@ fizzBuzz (x:xs) = isFizzBuzz x : fizzBuzz xs | mod x 3 == 0 = "Fizz" | otherwise = show x --- Fibonnaci number at indice n +-- Fibonacci number at indice n fibonacci :: Int -> Int fibonacci 0 = 0 fibonacci 1 = 1 fibonacci n = fibonacci (n - 1) + fibonacci (n - 2) --- Fibonnaci sequence until indice n -fibonnaciSequence :: Int -> [Int] -fibonnaciSequence 0 = [0] -fibonnaciSequence 1 = [0, 1] -fibonnaciSequence n = fibonnaciSequence (n - 1) ++ [fibonacci n] +-- Fibonaci sequence until indice n +fibonaciSequence :: Int -> [Int] +fibonaciSequence 0 = [0] +fibonaciSequence 1 = [0, 1] +fibonaciSequence n = fibonaciSequence (n - 1) ++ [fibonacci n] diff --git a/Math.hs b/app/Math.hs similarity index 100% rename from Math.hs rename to app/Math.hs diff --git a/Primes.hs b/app/Primes.hs similarity index 56% rename from Primes.hs rename to app/Primes.hs index 18968ec..2207baa 100644 --- a/Primes.hs +++ b/app/Primes.hs @@ -1,11 +1,11 @@ -module Primes ( aspGetNextPrime, aspIsPrime, aspPrimes ) where +--module Primes ( aspGetNextPrime, aspIsPrime, aspPrimes ) where +module Primes ( aspGetNextPrime, aspIsPrime ) where import Problems ( kth ) aspGetNextPrime :: Int -> Int aspGetNextPrime 1 = 2 aspGetNextPrime 2 = 3 -aspGetNextPrime n - | otherwise = aspGetNextPrime (n + 2) +aspGetNextPrime n = aspGetNextPrime (n + 2) aspIsPrime :: Int -> Bool aspIsPrime 1 = False @@ -17,5 +17,5 @@ aspIsPrime n = mod n (aspGetNextPrime 1) == 0 --aspPrimeFactors 1 = [1] --aspPrimes :: (Integral Int) => [Int] -aspPrimes = sieve [2..] - where sieve (x:xs) = [ x | x <- xs, x mod p == 0] +--aspPrimes = sieve [2..] +-- where sieve (x:xs) = [ x | x <- xs, x mod p == 0] diff --git a/Problems.hs b/app/Problems.hs similarity index 100% rename from Problems.hs rename to app/Problems.hs diff --git a/haskell-playground.cabal b/haskell-playground.cabal new file mode 100644 index 0000000..c24d167 --- /dev/null +++ b/haskell-playground.cabal @@ -0,0 +1,16 @@ +cabal-version: 2.4 +name: haskell-playground +version: 0.1.0.0 +author: saundersp +maintainer: pierre.saundersgb@gmail.com + +executable haskell-playground + main-is: Main.hs + build-depends: + primes, + base ^>=4.16.4.0 + other-modules: + Primes + Problems + hs-source-dirs: app + default-language: Haskell2010