├── .gitignore ├── Arithmetic ├── .gitignore ├── Arithmetic.cabal ├── Problems.hs ├── README.md ├── Tests.hs └── stack.yaml ├── Functions ├── .gitignore ├── Functions.cabal ├── Problems.hs ├── README.md ├── Tests.hs └── stack.yaml ├── Functors ├── .gitignore ├── Functors.cabal ├── Problems.hs ├── README.md ├── Tests.hs └── stack.yaml ├── Lists ├── .gitignore ├── Lists.cabal ├── Problems.hs ├── README.md ├── Tests.hs └── stack.yaml ├── Logic ├── .gitignore ├── Logic.cabal ├── Problems.hs ├── README.md ├── Tests.hs └── stack.yaml ├── README.md ├── TypeClasses ├── .gitignore ├── Problems.hs ├── README.md ├── Tests.hs ├── TypeClasses.cabal └── stack.yaml ├── folder-template.hsfiles └── img └── progression-path.png /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | -------------------------------------------------------------------------------- /Arithmetic/.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | dist-* 3 | cabal-dev 4 | *.o 5 | *.hi 6 | *.chi 7 | *.chs.h 8 | *.dyn_o 9 | *.dyn_hi 10 | .hpc 11 | .hsenv 12 | .cabal-sandbox/ 13 | cabal.sandbox.config 14 | *.prof 15 | *.aux 16 | *.hp 17 | *.eventlog 18 | .stack-work/ 19 | cabal.project.local 20 | .HTF/ 21 | .ghc.environment.* 22 | *~ -------------------------------------------------------------------------------- /Arithmetic/Arithmetic.cabal: -------------------------------------------------------------------------------- 1 | name: Arithmetic 2 | version: 0.1.0.0 3 | -- synopsis: 4 | -- description: 5 | homepage: https://github.com/jd95/Arithmetic#readme 6 | author: Jeff 7 | maintainer: jeffreydwyer95@outlook.com 8 | category: Web 9 | build-type: Simple 10 | cabal-version: >=1.10 11 | extra-source-files: README.md 12 | 13 | library 14 | hs-source-dirs: . 15 | exposed-modules: Problems 16 | default-language: Haskell2010 17 | build-depends: base >= 4.7 && < 5 18 | 19 | test-suite check-answers 20 | type: exitcode-stdio-1.0 21 | hs-source-dirs: . 22 | main-is: Tests.hs 23 | build-depends: base 24 | , Arithmetic 25 | , hspec 26 | , QuickCheck 27 | ghc-options: -threaded -rtsopts -with-rtsopts=-N 28 | default-language: Haskell2010 29 | -------------------------------------------------------------------------------- /Arithmetic/Problems.hs: -------------------------------------------------------------------------------- 1 | module Problems where 2 | 3 | {- | 4 | 5 | Sum of two numbers 6 | 7 | Implement the function to add the two given numbers. 8 | 9 | Example: 10 | 11 | > add 5 6 = 11 12 | 13 | -} 14 | add :: Int -> Int -> Int 15 | add x y = undefined 16 | 17 | {- | 18 | 19 | Difference of two numbers 20 | 21 | Implement the function to subtract two given numbers. 22 | 23 | Example: 24 | 25 | > subtract 5 6 = -1 26 | 27 | -} 28 | subtract :: Int -> Int -> Int 29 | subtract x y = undefined 30 | 31 | {- | 32 | 33 | Multiplication of two numbers 34 | 35 | Implement the function to multiply two given numbers. 36 | 37 | Example: 38 | 39 | > mult 5 6 = 30 40 | 41 | -} 42 | mult :: Int -> Int -> Int 43 | mult x y = undefined 44 | 45 | {- | 46 | 47 | Integer Division 48 | 49 | Implement the function to divide the first number by the second to 50 | give an integer. 51 | 52 | Example: 53 | 54 | > division 6 2 = 3 55 | > division 15 4 = 3 56 | 57 | -} 58 | division :: Int -> Int -> Int 59 | division x y = undefined 60 | 61 | {- | 62 | 63 | Modulus 64 | 65 | Implement the function to take the modulus of the first number by the second. 66 | 67 | Example: 68 | 69 | > modulus 6 4 = 2 70 | > modulus 9 3 = 0 71 | 72 | -} 73 | modulus :: Int -> Int -> Int 74 | modulus x y = undefined 75 | -------------------------------------------------------------------------------- /Arithmetic/README.md: -------------------------------------------------------------------------------- 1 | # Arithmetic Problem Set 2 | 3 | ## Resources 4 | - [Learn You A Haskell](http://learnyouahaskell.com/starting-out) 5 | -------------------------------------------------------------------------------- /Arithmetic/Tests.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE ScopedTypeVariables #-} 2 | 3 | module Main where 4 | 5 | import Test.Hspec 6 | import Test.QuickCheck 7 | 8 | import qualified Problems as P 9 | 10 | main :: IO () 11 | main = hspec $ do 12 | describe "Problem 1" $ do 13 | it "should add two numbers" $ 14 | property $ \(x :: Int, y :: Int) -> 15 | P.add x y == (x + y) 16 | 17 | describe "Problem 2" $ 18 | it "should subtract two numbers" $ 19 | property $ \(x :: Int, y :: Int) -> 20 | P.subtract x y == (x - y) 21 | 22 | describe "Problem 3" $ 23 | it "should multiply two numbers" $ 24 | property $ \(x :: Int, y :: Int) -> 25 | P.mult x y == (x * y) 26 | 27 | describe "Problem 4" $ 28 | it "should perform integer division" $ 29 | property $ \(x :: Int, y :: Int) -> 30 | P.division x y == (x `div` y) 31 | 32 | describe "Problem 5" $ 33 | it "should perform modulus" $ 34 | property $ \(x :: Int, y :: Int) -> 35 | P.modulus x y == (x `mod` y) 36 | -------------------------------------------------------------------------------- /Arithmetic/stack.yaml: -------------------------------------------------------------------------------- 1 | # This file was automatically generated by 'stack init' 2 | # 3 | # Some commonly used options have been documented as comments in this file. 4 | # For advanced use and comprehensive documentation of the format, please see: 5 | # https://docs.haskellstack.org/en/stable/yaml_configuration/ 6 | 7 | # Resolver to choose a 'specific' stackage snapshot or a compiler version. 8 | # A snapshot resolver dictates the compiler version and the set of packages 9 | # to be used for project dependencies. For example: 10 | # 11 | # resolver: lts-3.5 12 | # resolver: nightly-2015-09-21 13 | # resolver: ghc-7.10.2 14 | # resolver: ghcjs-0.1.0_ghc-7.10.2 15 | # resolver: 16 | # name: custom-snapshot 17 | # location: "./custom-snapshot.yaml" 18 | resolver: lts-9.5 19 | 20 | # User packages to be built. 21 | # Various formats can be used as shown in the example below. 22 | # 23 | # packages: 24 | # - some-directory 25 | # - https://example.com/foo/bar/baz-0.0.2.tar.gz 26 | # - location: 27 | # git: https://github.com/commercialhaskell/stack.git 28 | # commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a 29 | # - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a 30 | # extra-dep: true 31 | # subdirs: 32 | # - auto-update 33 | # - wai 34 | # 35 | # A package marked 'extra-dep: true' will only be built if demanded by a 36 | # non-dependency (i.e. a user package), and its test suites and benchmarks 37 | # will not be run. This is useful for tweaking upstream packages. 38 | packages: 39 | - . 40 | # Dependency packages to be pulled from upstream that are not in the resolver 41 | # (e.g., acme-missiles-0.3) 42 | extra-deps: [] 43 | 44 | # Override default flag values for local packages and extra-deps 45 | flags: {} 46 | 47 | # Extra package databases containing global packages 48 | extra-package-dbs: [] 49 | 50 | # Control whether we use the GHC we find on the path 51 | # system-ghc: true 52 | # 53 | # Require a specific version of stack, using version ranges 54 | # require-stack-version: -any # Default 55 | # require-stack-version: ">=1.5" 56 | # 57 | # Override the architecture used by stack, especially useful on Windows 58 | # arch: i386 59 | # arch: x86_64 60 | # 61 | # Extra directories used by stack for building 62 | # extra-include-dirs: [/path/to/dir] 63 | # extra-lib-dirs: [/path/to/dir] 64 | # 65 | # Allow a newer minor version of GHC than the snapshot specifies 66 | # compiler-check: newer-minor -------------------------------------------------------------------------------- /Functions/.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | dist-* 3 | cabal-dev 4 | *.o 5 | *.hi 6 | *.chi 7 | *.chs.h 8 | *.dyn_o 9 | *.dyn_hi 10 | .hpc 11 | .hsenv 12 | .cabal-sandbox/ 13 | cabal.sandbox.config 14 | *.prof 15 | *.aux 16 | *.hp 17 | *.eventlog 18 | .stack-work/ 19 | cabal.project.local 20 | .HTF/ 21 | .ghc.environment.* 22 | *~ -------------------------------------------------------------------------------- /Functions/Functions.cabal: -------------------------------------------------------------------------------- 1 | name: Functions 2 | version: 0.1.0.0 3 | -- synopsis: 4 | -- description: 5 | homepage: https://github.com/githubuser/Functions#readme 6 | author: Author name here 7 | maintainer: example@example.com 8 | category: Web 9 | build-type: Simple 10 | cabal-version: >=1.10 11 | extra-source-files: README.md 12 | 13 | library 14 | hs-source-dirs: . 15 | exposed-modules: Problems 16 | default-language: Haskell2010 17 | build-depends: base >= 4.7 && < 5 18 | 19 | test-suite check-answers 20 | type: exitcode-stdio-1.0 21 | hs-source-dirs: . 22 | main-is: Tests.hs 23 | build-depends: base 24 | , Functions 25 | , hspec 26 | ghc-options: -threaded -rtsopts -with-rtsopts=-N 27 | default-language: Haskell2010 28 | -------------------------------------------------------------------------------- /Functions/Problems.hs: -------------------------------------------------------------------------------- 1 | module Problems where 2 | 3 | problem1 :: a -> a 4 | problem1 = undefined 5 | 6 | problem2 :: a -> b -> a 7 | problem2 = undefined 8 | 9 | problem3 :: (a -> b) -> a -> b 10 | problem3 = undefined 11 | 12 | problem4 :: a -> b -> (a, b) 13 | problem4 = undefined 14 | 15 | problem5 :: (a, b) -> (b, a) 16 | problem5 = undefined 17 | 18 | problem6 :: (a -> b -> c) -> ((a,b) -> c) 19 | problem6 = undefined 20 | 21 | problem7 :: ((a,b) -> c) -> (a -> b -> c) 22 | problem7 = undefined 23 | 24 | problem8 :: (b -> c) -> (a -> b) -> (a -> c) 25 | problem8 = undefined 26 | 27 | problem9 :: (a -> b) -> (e -> a) -> (e -> b) 28 | problem9 = undefined 29 | 30 | problem10 :: (e -> a -> b) -> (e -> a) -> (e -> b) 31 | problem10 = undefined 32 | 33 | problem11 :: (e -> a) -> (a -> (e -> b)) -> (e -> b) 34 | problem11 = undefined 35 | -------------------------------------------------------------------------------- /Functions/README.md: -------------------------------------------------------------------------------- 1 | # Functions Problem Set 2 | 3 | ### Concepts Covered: 4 | - Function Application 5 | - Currying 6 | - Lambdas 7 | - Composition 8 | 9 | These problems are for practice with the workings of functions in Haskell. All of the problems use completely generic types to focus solely on the mechanics of functions. 10 | 11 | 12 | -------------------------------------------------------------------------------- /Functions/Tests.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Test.Hspec 4 | 5 | import Problems 6 | 7 | main :: IO () 8 | main = hspec $ do 9 | describe "addition" $ do 10 | context "should always" $ do 11 | it "work" $ 12 | (1 + 1) `shouldBe` (2 :: Int) 13 | -------------------------------------------------------------------------------- /Functions/stack.yaml: -------------------------------------------------------------------------------- 1 | # This file was automatically generated by 'stack init' 2 | # 3 | # Some commonly used options have been documented as comments in this file. 4 | # For advanced use and comprehensive documentation of the format, please see: 5 | # https://docs.haskellstack.org/en/stable/yaml_configuration/ 6 | 7 | # Resolver to choose a 'specific' stackage snapshot or a compiler version. 8 | # A snapshot resolver dictates the compiler version and the set of packages 9 | # to be used for project dependencies. For example: 10 | # 11 | # resolver: lts-3.5 12 | # resolver: nightly-2015-09-21 13 | # resolver: ghc-7.10.2 14 | # resolver: ghcjs-0.1.0_ghc-7.10.2 15 | # resolver: 16 | # name: custom-snapshot 17 | # location: "./custom-snapshot.yaml" 18 | resolver: lts-9.6 19 | 20 | # User packages to be built. 21 | # Various formats can be used as shown in the example below. 22 | # 23 | # packages: 24 | # - some-directory 25 | # - https://example.com/foo/bar/baz-0.0.2.tar.gz 26 | # - location: 27 | # git: https://github.com/commercialhaskell/stack.git 28 | # commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a 29 | # - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a 30 | # extra-dep: true 31 | # subdirs: 32 | # - auto-update 33 | # - wai 34 | # 35 | # A package marked 'extra-dep: true' will only be built if demanded by a 36 | # non-dependency (i.e. a user package), and its test suites and benchmarks 37 | # will not be run. This is useful for tweaking upstream packages. 38 | packages: 39 | - . 40 | # Dependency packages to be pulled from upstream that are not in the resolver 41 | # (e.g., acme-missiles-0.3) 42 | extra-deps: [] 43 | 44 | # Override default flag values for local packages and extra-deps 45 | flags: {} 46 | 47 | # Extra package databases containing global packages 48 | extra-package-dbs: [] 49 | 50 | # Control whether we use the GHC we find on the path 51 | # system-ghc: true 52 | # 53 | # Require a specific version of stack, using version ranges 54 | # require-stack-version: -any # Default 55 | # require-stack-version: ">=1.5" 56 | # 57 | # Override the architecture used by stack, especially useful on Windows 58 | # arch: i386 59 | # arch: x86_64 60 | # 61 | # Extra directories used by stack for building 62 | # extra-include-dirs: [/path/to/dir] 63 | # extra-lib-dirs: [/path/to/dir] 64 | # 65 | # Allow a newer minor version of GHC than the snapshot specifies 66 | # compiler-check: newer-minor -------------------------------------------------------------------------------- /Functors/.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | dist-* 3 | cabal-dev 4 | *.o 5 | *.hi 6 | *.chi 7 | *.chs.h 8 | *.dyn_o 9 | *.dyn_hi 10 | .hpc 11 | .hsenv 12 | .cabal-sandbox/ 13 | cabal.sandbox.config 14 | *.prof 15 | *.aux 16 | *.hp 17 | *.eventlog 18 | .stack-work/ 19 | cabal.project.local 20 | .HTF/ 21 | .ghc.environment.* 22 | *~ -------------------------------------------------------------------------------- /Functors/Functors.cabal: -------------------------------------------------------------------------------- 1 | name: Functors 2 | version: 0.1.0.0 3 | -- synopsis: 4 | -- description: 5 | homepage: https://github.com/jd95/Functors#readme 6 | author: Jeff 7 | maintainer: jeffreydwyer95@outlook.com 8 | category: Web 9 | build-type: Simple 10 | cabal-version: >=1.10 11 | extra-source-files: README.md 12 | 13 | library 14 | hs-source-dirs: . 15 | exposed-modules: Problems 16 | default-language: Haskell2010 17 | build-depends: base >= 4.7 && < 5 18 | 19 | test-suite check-answers 20 | type: exitcode-stdio-1.0 21 | hs-source-dirs: . 22 | main-is: Tests.hs 23 | build-depends: base 24 | , Functors 25 | , hspec 26 | ghc-options: -threaded -rtsopts -with-rtsopts=-N 27 | default-language: Haskell2010 28 | -------------------------------------------------------------------------------- /Functors/Problems.hs: -------------------------------------------------------------------------------- 1 | module Problems where 2 | -------------------------------------------------------------------------------- /Functors/README.md: -------------------------------------------------------------------------------- 1 | # Functors Problem Set 2 | 3 | ### Concepts Covered: 4 | - fmap 5 | - Maybe 6 | - Either 7 | - Reader 8 | - State 9 | 10 | ## Resources 11 | - [Learn You A Haskell](http://learnyouahaskell.com/functors-applicative-functors-and-monoids) 12 | - [Wikibooks](https://en.wikibooks.org/wiki/Haskell/The_Functor_class) 13 | - [Typeclassopedia](https://wiki.haskell.org/Typeclassopedia#Functor) 14 | -------------------------------------------------------------------------------- /Functors/Tests.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Test.Hspec 4 | 5 | import Problems 6 | 7 | main :: IO () 8 | main = hspec $ do 9 | describe "addition" $ do 10 | context "should always" $ do 11 | it "work" $ 12 | (1 + 1) `shouldBe` (2 :: Int) 13 | -------------------------------------------------------------------------------- /Functors/stack.yaml: -------------------------------------------------------------------------------- 1 | # This file was automatically generated by 'stack init' 2 | # 3 | # Some commonly used options have been documented as comments in this file. 4 | # For advanced use and comprehensive documentation of the format, please see: 5 | # https://docs.haskellstack.org/en/stable/yaml_configuration/ 6 | 7 | # Resolver to choose a 'specific' stackage snapshot or a compiler version. 8 | # A snapshot resolver dictates the compiler version and the set of packages 9 | # to be used for project dependencies. For example: 10 | # 11 | # resolver: lts-3.5 12 | # resolver: nightly-2015-09-21 13 | # resolver: ghc-7.10.2 14 | # resolver: ghcjs-0.1.0_ghc-7.10.2 15 | # resolver: 16 | # name: custom-snapshot 17 | # location: "./custom-snapshot.yaml" 18 | resolver: lts-9.5 19 | 20 | # User packages to be built. 21 | # Various formats can be used as shown in the example below. 22 | # 23 | # packages: 24 | # - some-directory 25 | # - https://example.com/foo/bar/baz-0.0.2.tar.gz 26 | # - location: 27 | # git: https://github.com/commercialhaskell/stack.git 28 | # commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a 29 | # - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a 30 | # extra-dep: true 31 | # subdirs: 32 | # - auto-update 33 | # - wai 34 | # 35 | # A package marked 'extra-dep: true' will only be built if demanded by a 36 | # non-dependency (i.e. a user package), and its test suites and benchmarks 37 | # will not be run. This is useful for tweaking upstream packages. 38 | packages: 39 | - . 40 | # Dependency packages to be pulled from upstream that are not in the resolver 41 | # (e.g., acme-missiles-0.3) 42 | extra-deps: [] 43 | 44 | # Override default flag values for local packages and extra-deps 45 | flags: {} 46 | 47 | # Extra package databases containing global packages 48 | extra-package-dbs: [] 49 | 50 | # Control whether we use the GHC we find on the path 51 | # system-ghc: true 52 | # 53 | # Require a specific version of stack, using version ranges 54 | # require-stack-version: -any # Default 55 | # require-stack-version: ">=1.5" 56 | # 57 | # Override the architecture used by stack, especially useful on Windows 58 | # arch: i386 59 | # arch: x86_64 60 | # 61 | # Extra directories used by stack for building 62 | # extra-include-dirs: [/path/to/dir] 63 | # extra-lib-dirs: [/path/to/dir] 64 | # 65 | # Allow a newer minor version of GHC than the snapshot specifies 66 | # compiler-check: newer-minor -------------------------------------------------------------------------------- /Lists/.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | dist-* 3 | cabal-dev 4 | *.o 5 | *.hi 6 | *.chi 7 | *.chs.h 8 | *.dyn_o 9 | *.dyn_hi 10 | .hpc 11 | .hsenv 12 | .cabal-sandbox/ 13 | cabal.sandbox.config 14 | *.prof 15 | *.aux 16 | *.hp 17 | *.eventlog 18 | .stack-work/ 19 | cabal.project.local 20 | .HTF/ 21 | .ghc.environment.* 22 | *~ -------------------------------------------------------------------------------- /Lists/Lists.cabal: -------------------------------------------------------------------------------- 1 | name: Lists 2 | version: 0.1.0.0 3 | -- synopsis: 4 | -- description: 5 | homepage: https://github.com/jd95/Lists#readme 6 | author: Jeff 7 | maintainer: jeffreydwyer95@outlook.com 8 | category: Web 9 | build-type: Simple 10 | cabal-version: >=1.10 11 | extra-source-files: README.md 12 | 13 | library 14 | hs-source-dirs: . 15 | exposed-modules: Problems 16 | default-language: Haskell2010 17 | build-depends: base >= 4.7 && < 5 18 | 19 | test-suite check-answers 20 | type: exitcode-stdio-1.0 21 | hs-source-dirs: . 22 | main-is: Tests.hs 23 | build-depends: base 24 | , Lists 25 | , hspec 26 | , QuickCheck 27 | ghc-options: -threaded -rtsopts -with-rtsopts=-N 28 | default-language: Haskell2010 29 | -------------------------------------------------------------------------------- /Lists/Problems.hs: -------------------------------------------------------------------------------- 1 | module Problems where 2 | 3 | {- | 4 | 5 | Find the last element of a list 6 | 7 | eg. problem1 [1,2,3,4,5] 8 | 5 9 | -} 10 | last' :: [a] -> a 11 | last' xs = undefined 12 | 13 | {- | 14 | 15 | Find the second to last element of a list 16 | 17 | eg. problem2 [1,2,3,4,5] 18 | 4 19 | -} 20 | secondLast' :: [a] -> a 21 | secondLast' xs = undefined 22 | 23 | {- | 24 | 25 | Find the nth element of a list 26 | 27 | eg. nthElem [1,2,3,4,5] 0 28 | 1 29 | 30 | nthElem [1,2,3,4,5] 4 31 | 5 32 | 33 | nthElem [1,2,3,4,5] 2 34 | 3 35 | -} 36 | nthElem :: [a] -> Int -> a 37 | nthElem xs n = undefined 38 | 39 | {- | 40 | 41 | Find the length of a list 42 | 43 | eg. length [1,2,3,4] 44 | 4 45 | 46 | length [1] 47 | 1 48 | 49 | length [] 50 | 0 51 | -} 52 | length' :: [a] -> Int 53 | length' xs = undefined 54 | 55 | {- | 56 | 57 | Reverse a list 58 | 59 | eg. reverse [1,2,3] 60 | [3,2,1] 61 | 62 | reverse [] 63 | [] 64 | -} 65 | reverse' :: [a] -> [a] 66 | reverse' xs = undefined 67 | 68 | {- | 69 | 70 | Determine if list is a palindrome 71 | 72 | eg. palindrome [1,2,3] 73 | false 74 | 75 | palindrome [1,2,3,3,2,1] 76 | true 77 | -} 78 | palindrome :: Eq a => [a] -> Bool 79 | palindrome xs = undefined 80 | 81 | {- | 82 | 83 | sum 84 | 85 | Add all numerical values in a list 86 | 87 | eg. sum [1,2,3,4] 88 | 10 89 | -} 90 | sum' :: Num a => [a] -> a 91 | sum' = undefined 92 | 93 | {- | 94 | 95 | zip 96 | 97 | Given two lists, create a new list of pairs 98 | with the left value being from the first list 99 | and the second value being from the second list. 100 | 101 | eg. zip [1,2,3,4] ['a', 'b', 'c', 'd'] 102 | [(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd')] 103 | -} 104 | zip' :: [a] -> [b] -> [(a,b)] 105 | zip' = undefined 106 | 107 | {- | 108 | 109 | zipWith 110 | 111 | Given a function of two values, and two lists, 112 | create a new list which is the result of the function 113 | using values from both lists. 114 | 115 | eg. zipWith (+) [1,2,3,4] [1,2,3,4] 116 | [2,4,6,8] 117 | -} 118 | zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c] 119 | zipWith' = undefined 120 | -------------------------------------------------------------------------------- /Lists/README.md: -------------------------------------------------------------------------------- 1 | # Lists Problem Set 2 | 3 | ### Concepts Covered: 4 | - take 5 | - drop 6 | - fold 7 | - zip 8 | - iterate 9 | - intersperse 10 | 11 | ## Resources 12 | - [Wikibooks](https://en.wikibooks.org/wiki/Haskell/Lists_and_tuples) 13 | - [Learn You A Haskell](http://learnyouahaskell.com/starting-out) 14 | -------------------------------------------------------------------------------- /Lists/Tests.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE ScopedTypeVariables #-} 2 | module Main where 3 | 4 | import Test.Hspec 5 | import Test.QuickCheck 6 | import Control.Arrow 7 | 8 | import Problems 9 | 10 | main :: IO () 11 | main = hspec $ do 12 | describe "Problem 1" $ do 13 | it "should get last element" $ 14 | property $ \(x :: [Int]) -> 15 | last' x == last x 16 | 17 | describe "Problem 2" $ do 18 | it "should get the second to last element" $ 19 | property $ \(x :: [Int]) -> 20 | secondLast' x == (last . init $ x) 21 | 22 | describe "Problem 3" $ do 23 | it "should get the nth element" $ 24 | property $ \(x :: [Int]) (n :: Int) -> 25 | nthElem x n == (x !! n) 26 | 27 | describe "Problem 4" $ do 28 | it "should calculate the length of the list" $ 29 | property $ \(x :: [Int]) -> 30 | length' x == length x 31 | 32 | describe "Problem 5" $ do 33 | it "should reverse the list" $ 34 | property $ \(x :: [Int]) -> 35 | reverse' x == reverse x 36 | 37 | describe "Problem 6" $ do 38 | it "should find valid palindromes" $ 39 | property $ \(x :: Int) (isPal :: Bool) -> 40 | let list = [1..x] 41 | pal = if isPal then list ++ reverse list else list 42 | in palindrome pal == isPal 43 | 44 | describe "Problem 7" $ do 45 | it "should sum the list" $ 46 | property $ \(x :: [Int]) -> 47 | sum' x == sum x 48 | 49 | describe "Problem 8" $ do 50 | it "should zip two lists" $ 51 | property $ \(x :: [Int], y :: [Int]) -> 52 | zip' x y == zip x y 53 | 54 | describe "Problem 9" $ do 55 | it "should zip with the provided function" $ 56 | property $ \(xs :: [Int]) -> 57 | let xs' = zipWith' (+) xs xs 58 | in all id $ zipWith (\x x' -> x' == x + x) xs xs' 59 | -------------------------------------------------------------------------------- /Lists/stack.yaml: -------------------------------------------------------------------------------- 1 | # This file was automatically generated by 'stack init' 2 | # 3 | # Some commonly used options have been documented as comments in this file. 4 | # For advanced use and comprehensive documentation of the format, please see: 5 | # https://docs.haskellstack.org/en/stable/yaml_configuration/ 6 | 7 | # Resolver to choose a 'specific' stackage snapshot or a compiler version. 8 | # A snapshot resolver dictates the compiler version and the set of packages 9 | # to be used for project dependencies. For example: 10 | # 11 | # resolver: lts-3.5 12 | # resolver: nightly-2015-09-21 13 | # resolver: ghc-7.10.2 14 | # resolver: ghcjs-0.1.0_ghc-7.10.2 15 | # resolver: 16 | # name: custom-snapshot 17 | # location: "./custom-snapshot.yaml" 18 | resolver: lts-9.5 19 | 20 | # User packages to be built. 21 | # Various formats can be used as shown in the example below. 22 | # 23 | # packages: 24 | # - some-directory 25 | # - https://example.com/foo/bar/baz-0.0.2.tar.gz 26 | # - location: 27 | # git: https://github.com/commercialhaskell/stack.git 28 | # commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a 29 | # - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a 30 | # extra-dep: true 31 | # subdirs: 32 | # - auto-update 33 | # - wai 34 | # 35 | # A package marked 'extra-dep: true' will only be built if demanded by a 36 | # non-dependency (i.e. a user package), and its test suites and benchmarks 37 | # will not be run. This is useful for tweaking upstream packages. 38 | packages: 39 | - . 40 | # Dependency packages to be pulled from upstream that are not in the resolver 41 | # (e.g., acme-missiles-0.3) 42 | extra-deps: [] 43 | 44 | # Override default flag values for local packages and extra-deps 45 | flags: {} 46 | 47 | # Extra package databases containing global packages 48 | extra-package-dbs: [] 49 | 50 | # Control whether we use the GHC we find on the path 51 | # system-ghc: true 52 | # 53 | # Require a specific version of stack, using version ranges 54 | # require-stack-version: -any # Default 55 | # require-stack-version: ">=1.5" 56 | # 57 | # Override the architecture used by stack, especially useful on Windows 58 | # arch: i386 59 | # arch: x86_64 60 | # 61 | # Extra directories used by stack for building 62 | # extra-include-dirs: [/path/to/dir] 63 | # extra-lib-dirs: [/path/to/dir] 64 | # 65 | # Allow a newer minor version of GHC than the snapshot specifies 66 | # compiler-check: newer-minor -------------------------------------------------------------------------------- /Logic/.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | dist-* 3 | cabal-dev 4 | *.o 5 | *.hi 6 | *.chi 7 | *.chs.h 8 | *.dyn_o 9 | *.dyn_hi 10 | .hpc 11 | .hsenv 12 | .cabal-sandbox/ 13 | cabal.sandbox.config 14 | *.prof 15 | *.aux 16 | *.hp 17 | *.eventlog 18 | .stack-work/ 19 | cabal.project.local 20 | .HTF/ 21 | .ghc.environment.* 22 | *~ -------------------------------------------------------------------------------- /Logic/Logic.cabal: -------------------------------------------------------------------------------- 1 | name: Logic 2 | version: 0.1.0.0 3 | -- synopsis: 4 | -- description: 5 | homepage: https://github.com/jd95/Logic#readme 6 | author: Jeff 7 | maintainer: jeffreydwyer95@outlook.com 8 | category: Web 9 | build-type: Simple 10 | cabal-version: >=1.10 11 | extra-source-files: README.md 12 | 13 | library 14 | hs-source-dirs: . 15 | exposed-modules: Problems 16 | default-language: Haskell2010 17 | build-depends: base >= 4.7 && < 5 18 | 19 | test-suite check-answers 20 | type: exitcode-stdio-1.0 21 | hs-source-dirs: . 22 | main-is: Tests.hs 23 | build-depends: base 24 | , Logic 25 | , hspec 26 | , QuickCheck 27 | ghc-options: -threaded -rtsopts -with-rtsopts=-N 28 | default-language: Haskell2010 29 | -------------------------------------------------------------------------------- /Logic/Problems.hs: -------------------------------------------------------------------------------- 1 | module Problems where 2 | 3 | {- Problem 1: Implement Not 4 | -} 5 | problem1 :: Bool -> Bool 6 | problem1 = not 7 | 8 | {- Problem 2: Implement And 9 | -} 10 | problem2 :: Bool -> Bool -> Bool 11 | problem2 = undefined 12 | 13 | {- Problem 3: Implement Or 14 | -} 15 | problem3 :: Bool -> Bool -> Bool 16 | problem3 = undefined 17 | 18 | {- Problem 4: Is Positive 19 | Implement problem4 such that it returns 20 | true for all positive integers. 21 | -} 22 | problem4 :: Int -> Bool 23 | problem4 = undefined 24 | 25 | {- Problem 5: Is Under 100 26 | Implement problem5 such that it returns 27 | true for all numbers under 100. 28 | -} 29 | problem5 :: Int -> Bool 30 | problem5 = undefined 31 | 32 | {- Problem 6: Is 5 33 | Implement problem6 such that it only returns 34 | true when it is given 5. 35 | -} 36 | problem6 :: Int -> Bool 37 | problem6 = undefined 38 | -------------------------------------------------------------------------------- /Logic/README.md: -------------------------------------------------------------------------------- 1 | # Logic Problem Set 2 | 3 | ### Concepts Covered 4 | - Case Expressions 5 | - Pattern Matching 6 | - Bool Type 7 | - Logical Operators 8 | 9 | 10 | -------------------------------------------------------------------------------- /Logic/Tests.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE ScopedTypeVariables #-} 2 | module Main where 3 | 4 | import Test.Hspec 5 | import Test.QuickCheck 6 | 7 | import Problems 8 | 9 | main :: IO () 10 | main = hspec $ do 11 | describe "addition" $ do 12 | it "problem 1" $ 13 | property $ \(x :: Bool) -> 14 | (problem1 x) == (not x) 15 | 16 | -------------------------------------------------------------------------------- /Logic/stack.yaml: -------------------------------------------------------------------------------- 1 | # This file was automatically generated by 'stack init' 2 | # 3 | # Some commonly used options have been documented as comments in this file. 4 | # For advanced use and comprehensive documentation of the format, please see: 5 | # https://docs.haskellstack.org/en/stable/yaml_configuration/ 6 | 7 | # Resolver to choose a 'specific' stackage snapshot or a compiler version. 8 | # A snapshot resolver dictates the compiler version and the set of packages 9 | # to be used for project dependencies. For example: 10 | # 11 | # resolver: lts-3.5 12 | # resolver: nightly-2015-09-21 13 | # resolver: ghc-7.10.2 14 | # resolver: ghcjs-0.1.0_ghc-7.10.2 15 | # resolver: 16 | # name: custom-snapshot 17 | # location: "./custom-snapshot.yaml" 18 | resolver: lts-9.5 19 | 20 | # User packages to be built. 21 | # Various formats can be used as shown in the example below. 22 | # 23 | # packages: 24 | # - some-directory 25 | # - https://example.com/foo/bar/baz-0.0.2.tar.gz 26 | # - location: 27 | # git: https://github.com/commercialhaskell/stack.git 28 | # commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a 29 | # - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a 30 | # extra-dep: true 31 | # subdirs: 32 | # - auto-update 33 | # - wai 34 | # 35 | # A package marked 'extra-dep: true' will only be built if demanded by a 36 | # non-dependency (i.e. a user package), and its test suites and benchmarks 37 | # will not be run. This is useful for tweaking upstream packages. 38 | packages: 39 | - . 40 | # Dependency packages to be pulled from upstream that are not in the resolver 41 | # (e.g., acme-missiles-0.3) 42 | extra-deps: [] 43 | 44 | # Override default flag values for local packages and extra-deps 45 | flags: {} 46 | 47 | # Extra package databases containing global packages 48 | extra-package-dbs: [] 49 | 50 | # Control whether we use the GHC we find on the path 51 | # system-ghc: true 52 | # 53 | # Require a specific version of stack, using version ranges 54 | # require-stack-version: -any # Default 55 | # require-stack-version: ">=1.5" 56 | # 57 | # Override the architecture used by stack, especially useful on Windows 58 | # arch: i386 59 | # arch: x86_64 60 | # 61 | # Extra directories used by stack for building 62 | # extra-include-dirs: [/path/to/dir] 63 | # extra-lib-dirs: [/path/to/dir] 64 | # 65 | # Allow a newer minor version of GHC than the snapshot specifies 66 | # compiler-check: newer-minor -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Haskell Problem Sets 2 | 3 | A collection of problem sets for new Haskellers 4 | 5 | Each folder contains a small project with a Problems.hs file filled with stub functions. Implement the functions and then test your solutions via 6 | 7 | > stack test 8 | 9 | ![progression path](img/progression-path.png) 10 | 11 | ## Contributing Problems 12 | 13 | To add problems to a category, simply implement a stub for the function along with a comment describing what is expected. Along with the stub should be a spec in Tests.hs which then validates the problem. 14 | 15 | Here are some online problem sets you could draw on: 16 | - http://www.codeabbey.com/index/task_list 17 | - https://techiedelight.quora.com/500-Data-Structures-and-Algorithms-practice-problems-and-their-solutions 18 | - http://codeforces.com/problemset 19 | - http://codingbat.com/java 20 | - https://open.kattis.com/ 21 | - https://leetcode.com/problemset/all/ 22 | - http://wcipeg.com/problems 23 | - http://poj.org/problemlist 24 | - http://www.spoj.com/problems/classical/ 25 | - http://acm.timus.ru/problemset.aspx?space=1&page=all 26 | 27 | ### Keep in mind 28 | - It would be best if your test did not directly implement the function for the problem so curious eyes can't simply peek at the answer. 29 | - As much as you can, keep the concepts required to solve the problem limited to the ones covered in that folder. For example, don't require use of intersperse in a Functor problem. 30 | 31 | ## Contributing Folders 32 | 33 | These problem sets are meant to be practice with the various "foundational" concepts and libraries presented to people new to Haskell. While a tutorial for something like Aeson might be useful, it's unlikely to be very helpful to have problem sets for some obscure graphics package. 34 | 35 | ### Keep in mind 36 | - The project folders follow a specific template. Follow that template to avoid confusion. 37 | - Any resources you add to a folder's readme should be specifically related to the folder's concept. Don't simply link to the Haskell book and call it a day. 38 | - Likewise, if there is a talk or video you want to link to, make sure that it links to the point in the talk which is actually relevant. 39 | -------------------------------------------------------------------------------- /TypeClasses/.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | dist-* 3 | cabal-dev 4 | *.o 5 | *.hi 6 | *.chi 7 | *.chs.h 8 | *.dyn_o 9 | *.dyn_hi 10 | .hpc 11 | .hsenv 12 | .cabal-sandbox/ 13 | cabal.sandbox.config 14 | *.prof 15 | *.aux 16 | *.hp 17 | *.eventlog 18 | .stack-work/ 19 | cabal.project.local 20 | .HTF/ 21 | .ghc.environment.* 22 | *~ -------------------------------------------------------------------------------- /TypeClasses/Problems.hs: -------------------------------------------------------------------------------- 1 | module Problems where 2 | 3 | import Prelude (Bool, String, id) 4 | 5 | data Maybe a = Just a | Nothing 6 | 7 | data List a = Cons a (List a) | Nil 8 | 9 | newtype State s a = State { runState :: s -> (s, a)} 10 | 11 | class Show a where 12 | show :: a -> String 13 | 14 | class Eq a where 15 | (==) :: a -> a -> Bool 16 | 17 | class Semigroup a where 18 | (<>) :: a -> a -> a 19 | 20 | class Semigroup m => Monoid m where 21 | mempty :: m 22 | 23 | class Functor f where 24 | fmap :: (a -> b) -> f a -> f b 25 | 26 | class Functor f => Applicative f where 27 | pure :: a -> f a 28 | (<*>) :: f (a -> b) -> f a -> f b 29 | 30 | class Applicative f => Alternative f where 31 | empty :: f a 32 | (<|>) :: f a -> f a -> f a 33 | 34 | class Applicative m => Monad m where 35 | 36 | (>>=) :: m a -> (a -> m b) -> m b 37 | ma >>= f = join (fmap f ma) 38 | 39 | join :: m (m a) -> m a 40 | join m = m >>= id 41 | {-# MINIMAL (>>=) | join #-} 42 | -------------------------------------------------------------------------------- /TypeClasses/README.md: -------------------------------------------------------------------------------- 1 | # TypeClasses Problem Set 2 | -------------------------------------------------------------------------------- /TypeClasses/Tests.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Test.Hspec 4 | 5 | import Problems 6 | 7 | main :: IO () 8 | main = hspec $ do 9 | describe "addition" $ do 10 | context "should always" $ do 11 | it "work" $ 12 | (1 + 1) `shouldBe` (2 :: Int) 13 | -------------------------------------------------------------------------------- /TypeClasses/TypeClasses.cabal: -------------------------------------------------------------------------------- 1 | name: TypeClasses 2 | version: 0.1.0.0 3 | -- synopsis: 4 | -- description: 5 | homepage: https://github.com/jd95/TypeClasses#readme 6 | author: Jeff 7 | maintainer: jeffreydwyer95@outlook.com 8 | category: Web 9 | build-type: Simple 10 | cabal-version: >=1.10 11 | extra-source-files: README.md 12 | 13 | library 14 | hs-source-dirs: . 15 | exposed-modules: Problems 16 | default-language: Haskell2010 17 | build-depends: base >= 4.7 && < 5 18 | 19 | test-suite check-answers 20 | type: exitcode-stdio-1.0 21 | hs-source-dirs: . 22 | main-is: Tests.hs 23 | build-depends: base 24 | , TypeClasses 25 | , hspec 26 | ghc-options: -threaded -rtsopts -with-rtsopts=-N 27 | default-language: Haskell2010 28 | -------------------------------------------------------------------------------- /TypeClasses/stack.yaml: -------------------------------------------------------------------------------- 1 | # This file was automatically generated by 'stack init' 2 | # 3 | # Some commonly used options have been documented as comments in this file. 4 | # For advanced use and comprehensive documentation of the format, please see: 5 | # https://docs.haskellstack.org/en/stable/yaml_configuration/ 6 | 7 | # Resolver to choose a 'specific' stackage snapshot or a compiler version. 8 | # A snapshot resolver dictates the compiler version and the set of packages 9 | # to be used for project dependencies. For example: 10 | # 11 | # resolver: lts-3.5 12 | # resolver: nightly-2015-09-21 13 | # resolver: ghc-7.10.2 14 | # resolver: ghcjs-0.1.0_ghc-7.10.2 15 | # resolver: 16 | # name: custom-snapshot 17 | # location: "./custom-snapshot.yaml" 18 | resolver: lts-9.5 19 | 20 | # User packages to be built. 21 | # Various formats can be used as shown in the example below. 22 | # 23 | # packages: 24 | # - some-directory 25 | # - https://example.com/foo/bar/baz-0.0.2.tar.gz 26 | # - location: 27 | # git: https://github.com/commercialhaskell/stack.git 28 | # commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a 29 | # - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a 30 | # extra-dep: true 31 | # subdirs: 32 | # - auto-update 33 | # - wai 34 | # 35 | # A package marked 'extra-dep: true' will only be built if demanded by a 36 | # non-dependency (i.e. a user package), and its test suites and benchmarks 37 | # will not be run. This is useful for tweaking upstream packages. 38 | packages: 39 | - . 40 | # Dependency packages to be pulled from upstream that are not in the resolver 41 | # (e.g., acme-missiles-0.3) 42 | extra-deps: [] 43 | 44 | # Override default flag values for local packages and extra-deps 45 | flags: {} 46 | 47 | # Extra package databases containing global packages 48 | extra-package-dbs: [] 49 | 50 | # Control whether we use the GHC we find on the path 51 | # system-ghc: true 52 | # 53 | # Require a specific version of stack, using version ranges 54 | # require-stack-version: -any # Default 55 | # require-stack-version: ">=1.5" 56 | # 57 | # Override the architecture used by stack, especially useful on Windows 58 | # arch: i386 59 | # arch: x86_64 60 | # 61 | # Extra directories used by stack for building 62 | # extra-include-dirs: [/path/to/dir] 63 | # extra-lib-dirs: [/path/to/dir] 64 | # 65 | # Allow a newer minor version of GHC than the snapshot specifies 66 | # compiler-check: newer-minor -------------------------------------------------------------------------------- /folder-template.hsfiles: -------------------------------------------------------------------------------- 1 | {-# START_FILE {{name}}.cabal #-} 2 | name: {{name}} 3 | version: 0.1.0.0 4 | -- synopsis: 5 | -- description: 6 | homepage: https://github.com/{{github-username}}{{^github-username}}githubuser{{/github-username}}/{{name}}#readme 7 | author: {{author-name}}{{^author-name}}Author name here{{/author-name}} 8 | maintainer: {{author-email}}{{^author-email}}example@example.com{{/author-email}} 9 | category: {{category}}{{^category}}Web{{/category}} 10 | build-type: Simple 11 | cabal-version: >=1.10 12 | extra-source-files: README.md 13 | 14 | library 15 | hs-source-dirs: . 16 | exposed-modules: Problems 17 | default-language: Haskell2010 18 | build-depends: base >= 4.7 && < 5 19 | 20 | test-suite check-answers 21 | type: exitcode-stdio-1.0 22 | hs-source-dirs: . 23 | main-is: Tests.hs 24 | build-depends: base 25 | , {{name}} 26 | , hspec 27 | ghc-options: -threaded -rtsopts -with-rtsopts=-N 28 | default-language: Haskell2010 29 | 30 | {-# START_FILE README.md #-} 31 | # {{name}} Problem Set 32 | 33 | {-# START_FILE Problems.hs #-} 34 | module Problems where 35 | 36 | {-# START_FILE Tests.hs #-} 37 | module Main where 38 | 39 | import Test.Hspec 40 | 41 | import Problems 42 | 43 | main :: IO () 44 | main = hspec $ do 45 | describe "addition" $ do 46 | context "should always" $ do 47 | it "work" $ 48 | (1 + 1) `shouldBe` (2 :: Int) 49 | 50 | {-# START_FILE .gitignore #-} 51 | dist 52 | dist-* 53 | cabal-dev 54 | *.o 55 | *.hi 56 | *.chi 57 | *.chs.h 58 | *.dyn_o 59 | *.dyn_hi 60 | .hpc 61 | .hsenv 62 | .cabal-sandbox/ 63 | cabal.sandbox.config 64 | *.prof 65 | *.aux 66 | *.hp 67 | *.eventlog 68 | .stack-work/ 69 | cabal.project.local 70 | .HTF/ 71 | .ghc.environment.* 72 | *~ -------------------------------------------------------------------------------- /img/progression-path.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JD95/haskell-problem-sets/b23deb8b5410c05be896f219abc839734c8812fc/img/progression-path.png --------------------------------------------------------------------------------