diff options
Diffstat (limited to 'Haskell-book/04')
| -rw-r--r-- | Haskell-book/04/.gitignore | 8 | ||||
| -rw-r--r-- | Haskell-book/04/bower.json | 20 | ||||
| -rw-r--r-- | Haskell-book/04/src/Ex.purs | 33 | ||||
| -rw-r--r-- | Haskell-book/04/src/Main.purs | 9 | ||||
| -rw-r--r-- | Haskell-book/04/test/Main.purs | 9 |
5 files changed, 79 insertions, 0 deletions
diff --git a/Haskell-book/04/.gitignore b/Haskell-book/04/.gitignore new file mode 100644 index 0000000..9623fa5 --- /dev/null +++ b/Haskell-book/04/.gitignore @@ -0,0 +1,8 @@ +/bower_components/ +/node_modules/ +/.pulp-cache/ +/output/ +/generated-docs/ +/.psc* +/.purs* +/.psa* diff --git a/Haskell-book/04/bower.json b/Haskell-book/04/bower.json new file mode 100644 index 0000000..e6c4ee1 --- /dev/null +++ b/Haskell-book/04/bower.json @@ -0,0 +1,20 @@ +{ + "name": "04", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "output" + ], + "dependencies": { + "purescript-prelude": "^3.1.0", + "purescript-console": "^3.0.0", + "purescript-tuples": "^4.1.0", + "purescript-lists": "^4.10.0", + "purescript-arrays": "^4.2.1", + "purescript-strings": "^3.3.1" + }, + "devDependencies": { + "purescript-psci-support": "^3.0.0" + } +} diff --git a/Haskell-book/04/src/Ex.purs b/Haskell-book/04/src/Ex.purs new file mode 100644 index 0000000..38da5c4 --- /dev/null +++ b/Haskell-book/04/src/Ex.purs @@ -0,0 +1,33 @@ +module Ex where + +import Prelude +import Data.Array (tail, reverse) +import Data.Maybe (Maybe(..)) +import Data.String (toCharArray) +import Data.Tuple (fst, snd, Tuple(..)) + +awesome :: Array String +awesome = ["Papuchon", "curry", ":)"] + +alsoAwesome :: Array String +alsoAwesome = ["Quake", "The Simons"] + +allAwesome :: Array (Array String) +allAwesome = [awesome, alsoAwesome] + +length :: forall a. Array a -> Int +length n = length' 0 (tail n) + where length' i Nothing = i + length' i (Just k) = length' (i + 1) (tail k) + +isPalindrome :: String -> Boolean +isPalindrome x = toCharArray x == reverse (toCharArray x) + +myAbs :: Int -> Int +myAbs a = if a > 0 then a else -a + +f :: forall a b c d. Tuple a b -> Tuple c d -> Tuple (Tuple b d) (Tuple a c) +f x y = Tuple (Tuple (snd x) (snd y)) (Tuple (fst x) (fst y)) + +f' :: forall a b. (Tuple a b) -> a +f' (Tuple a b) = a diff --git a/Haskell-book/04/src/Main.purs b/Haskell-book/04/src/Main.purs new file mode 100644 index 0000000..abe68ec --- /dev/null +++ b/Haskell-book/04/src/Main.purs @@ -0,0 +1,9 @@ +module Main where + +import Prelude +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.Console (CONSOLE, log) + +main :: forall e. Eff (console :: CONSOLE | e) Unit +main = do + log "Hello sailor!" diff --git a/Haskell-book/04/test/Main.purs b/Haskell-book/04/test/Main.purs new file mode 100644 index 0000000..845d0f4 --- /dev/null +++ b/Haskell-book/04/test/Main.purs @@ -0,0 +1,9 @@ +module Test.Main where + +import Prelude +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.Console (CONSOLE, log) + +main :: forall e. Eff (console :: CONSOLE | e) Unit +main = do + log "You should add some tests." |
