summaryrefslogtreecommitdiff
path: root/template
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-07-19 10:06:45 +0000
committerFuwn <[email protected]>2021-07-19 10:06:45 +0000
commitcd3647db7f365fd040f7e8248681bbc5f01030b8 (patch)
treeac4451382aa7db8bd9c700daa5a0c6ee1774926b /template
downloadhaskell-stack-template-cd3647db7f365fd040f7e8248681bbc5f01030b8.tar.xz
haskell-stack-template-cd3647db7f365fd040f7e8248681bbc5f01030b8.zip
feat(hst): :star:HEADmaster
Diffstat (limited to 'template')
-rw-r--r--template/package.yaml12
-rw-r--r--template/src/exe/Main.hs15
-rw-r--r--template/src/lib/Template.hs19
-rw-r--r--template/template.cabal33
4 files changed, 79 insertions, 0 deletions
diff --git a/template/package.yaml b/template/package.yaml
new file mode 100644
index 0000000..b180711
--- /dev/null
+++ b/template/package.yaml
@@ -0,0 +1,12 @@
+name: template
+version: 0.1.0
+description: A Haskell project template for use with Stack.
+dependencies:
+ - base
+library:
+ source-dirs: ./src/lib
+executable:
+ source-dirs: ./src/exe
+ main: Main
+ dependencies:
+ - template
diff --git a/template/src/exe/Main.hs b/template/src/exe/Main.hs
new file mode 100644
index 0000000..a174244
--- /dev/null
+++ b/template/src/exe/Main.hs
@@ -0,0 +1,15 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+
+module Main where
+
+import System.Environment ( getArgs )
+import Template ( fib )
+
+main :: IO ()
+main = do
+ -- https://lotz84.github.io/haskellbyexample/ex/command-line-arguments
+ args <- getArgs
+ let arg = head args
+
+ -- https://stackoverflow.com/a/20667721
+ print (fib (read arg :: Int))
diff --git a/template/src/lib/Template.hs b/template/src/lib/Template.hs
new file mode 100644
index 0000000..29103b2
--- /dev/null
+++ b/template/src/lib/Template.hs
@@ -0,0 +1,19 @@
+module Template
+ ( fib
+ ) where
+
+import Data.Bits
+import Data.List
+
+-- https://wiki.haskell.org/The_Fibonacci_sequence
+fib :: Int -> Integer
+fib n =
+ snd
+ . foldl_ fib_ (1, 0)
+ . dropWhile not
+ $ [ testBit n k | k <- let s = bitSize n in [s - 1, s - 2 .. 0] ]
+ where
+ fib_ (f, g) p | p = (f * (f + 2 * g), ss)
+ | otherwise = (ss, g * (2 * f - g))
+ where ss = f * f + g * g
+ foldl_ = foldl' -- '
diff --git a/template/template.cabal b/template/template.cabal
new file mode 100644
index 0000000..13b0e48
--- /dev/null
+++ b/template/template.cabal
@@ -0,0 +1,33 @@
+cabal-version: 1.12
+
+-- This file has been generated from package.yaml by hpack version 0.34.4.
+--
+-- see: https://github.com/sol/hpack
+
+name: template
+version: 0.1.0
+description: A Haskell project template for use with Stack.
+build-type: Simple
+
+library
+ exposed-modules:
+ Template
+ other-modules:
+ Paths_template
+ hs-source-dirs:
+ ./src/lib
+ build-depends:
+ base
+ default-language: Haskell2010
+
+executable template
+ main-is: Main.hs
+ other-modules:
+ Paths_template
+ hs-source-dirs:
+ ./src/exe
+ ghc-options: -main-is Main
+ build-depends:
+ base
+ , template
+ default-language: Haskell2010