summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--stack.yaml6
-rw-r--r--stack.yaml.lock12
-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
6 files changed, 97 insertions, 0 deletions
diff --git a/stack.yaml b/stack.yaml
new file mode 100644
index 0000000..d77ec6c
--- /dev/null
+++ b/stack.yaml
@@ -0,0 +1,6 @@
+# Use LTS of Stackage for GHC 8.4.4
+# https://www.stackage.org/lts-16.26
+resolver: lts-16.26
+# Local packages
+packages:
+ - ./template
diff --git a/stack.yaml.lock b/stack.yaml.lock
new file mode 100644
index 0000000..42b2990
--- /dev/null
+++ b/stack.yaml.lock
@@ -0,0 +1,12 @@
+# This file was autogenerated by Stack.
+# You should not edit this file by hand.
+# For more information, please see the documentation at:
+# https://docs.haskellstack.org/en/stable/lock_files
+
+snapshots:
+- original: lts-16.26
+ completed:
+ sha256: cdbc5db9c1afe80a5998247939027a0c7db92fa0f20b5cd01596ec3da628b622
+ url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/16/26.yaml
+ size: 533252
+packages: []
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