git.iko.soy/production-haskell
on master help sign in
.
commit661ab02d166912df292900586ad480984831b116 authoriko <mail@iko.soy> dateThu 27 Feb 2025, 18:34 (2 years ago) parent1c5d174
12 files changed+302−6
seminars/2/src/Task.hs+16−6 seminars/calc/.gitignore+2 seminars/calc/CHANGELOG.md+11 seminars/calc/LICENSE+26 seminars/calc/README.md+1 seminars/calc/Setup.hs+2 seminars/calc/app/Main.hs+6 seminars/calc/calc.cabal+76 seminars/calc/package.yaml+62 seminars/calc/src/Lib.hs+27 seminars/calc/stack.yaml+71 seminars/calc/test/Spec.hs+2
seminars/2/src/Task.hs+16−6
@@ -27,13 +27,16 @@ module Task
2727 saveTheDiabetic,
2828 calculateSugarDanger,
2929 runStRandom, genStIntDouble
30+ , foo
3031 )
3132where
3233
3334import System.Random
3435import Control.Monad
3536
36−newtype State s a = State { runState :: s -> IO (s, a) }
37+newtype State m s a = State { runState :: s -> (s, m a) }
38+newtype Reader m s a = Reader { runReader :: s -> m a }
39+type Foo s s' a = State (Reader Identity s') s a
3740
3841instance Functor (State s) where
3942 -- fmap :: (a -> b) -> functor a -> functor b
@@ -72,6 +75,9 @@ genStIntDouble = do
7275 double <- stRandom
7376 return (int, double)
7477
78+foo :: State StdGen [(Int, Double)]
79+foo = sequenceA [genStIntDouble, genStIntDouble]
80+
7581-- fold [] = mempty
7682-- fold (x: xs) = x <> fold xs
7783
@@ -135,19 +141,23 @@ destructFirstMonoid (FirstMonoid a) = a
135141--
136142-- >>> (destructLastMonoid . fold . fmap constructLastMonoid) []
137143-- Nothing
138−data LastMonoid a
144+data LastMonoid a = LastMonoid (Maybe a)
145+
146+instance Semigroup (LastMonoid a) where
147+ a <> LastMonoid Nothing = a
148+ _ <> LastMonoid (Just a) = LastMonoid (Just a)
139149
140−instance Semigroup (LastMonoid a)
141150
142−instance Monoid (LastMonoid a)
151+instance Monoid (LastMonoid a) where
152+ mempty = LastMonoid Nothing
143153
144154-- Warps an `a` in a `LastMonoid`.
145155constructLastMonoid :: a -> LastMonoid a
146−constructLastMonoid = error "TODO: constructLastMonoid"
156+constructLastMonoid a = LastMonoid (Just a)
147157
148158-- Unwraps the `a` from a `LastMonoid`, if there is one.
149159destructLastMonoid :: LastMonoid a -> Maybe a
150−destructLastMonoid = error "TODO: destructLastMonoid"
160+destructLastMonoid (LastMonoid a) = a
151161
152162-- _____ _ _ _ _
153163-- |_ _|__ __| | ___ | | (_)___| |_
seminars/calc/.gitignorenew file+2
@@ -0,0 +1,2 @@
1+.stack-work/
2+*~
seminars/calc/CHANGELOG.mdnew file+11
@@ -0,0 +1,11 @@
1+# Changelog for `calc`
2+
3+All notable changes to this project will be documented in this file.
4+
5+The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+and this project adheres to the
7+[Haskell Package Versioning Policy](https://pvp.haskell.org/).
8+
9+## Unreleased
10+
11+## 0.1.0.0 - YYYY-MM-DD
seminars/calc/LICENSEnew file+26
@@ -0,0 +1,26 @@
1+Copyright 2025 Author name here
2+
3+Redistribution and use in source and binary forms, with or without
4+modification, are permitted provided that the following conditions are met:
5+
6+1. Redistributions of source code must retain the above copyright notice, this
7+ list of conditions and the following disclaimer.
8+
9+2. Redistributions in binary form must reproduce the above copyright notice,
10+ this list of conditions and the following disclaimer in the documentation
11+ and/or other materials provided with the distribution.
12+
13+3. Neither the name of the copyright holder nor the names of its contributors
14+ may be used to endorse or promote products derived from this software
15+ without specific prior written permission.
16+
17+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
21+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
seminars/calc/README.mdnew file+1
@@ -0,0 +1 @@
1+# calc
seminars/calc/Setup.hsnew file+2
@@ -0,0 +1,2 @@
1+import Distribution.Simple
2+main = defaultMain
seminars/calc/app/Main.hsnew file+6
@@ -0,0 +1,6 @@
1+module Main (main) where
2+
3+import Lib
4+
5+main :: IO ()
6+main = server
seminars/calc/calc.cabalnew file+76
@@ -0,0 +1,76 @@
1+cabal-version: 2.2
2+
3+-- This file has been generated from package.yaml by hpack version 0.37.0.
4+--
5+-- see: https://github.com/sol/hpack
6+
7+name: calc
8+version: 0.1.0.0
9+description: Please see the README on GitHub at <https://github.com/githubuser/calc#readme>
10+homepage: https://github.com/githubuser/calc#readme
11+bug-reports: https://github.com/githubuser/calc/issues
12+author: Author name here
13+maintainer: example@example.com
14+copyright: 2025 Author name here
15+license: BSD-3-Clause
16+license-file: LICENSE
17+build-type: Simple
18+extra-source-files:
19+ README.md
20+ CHANGELOG.md
21+
22+source-repository head
23+ type: git
24+ location: https://github.com/githubuser/calc
25+
26+library
27+ exposed-modules:
28+ Lib
29+ other-modules:
30+ Paths_calc
31+ autogen-modules:
32+ Paths_calc
33+ hs-source-dirs:
34+ src
35+ ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints
36+ build-depends:
37+ base >=4.7 && <5
38+ , mtl
39+ , scotty
40+ , text
41+ default-language: Haskell2010
42+
43+executable calc-exe
44+ main-is: Main.hs
45+ other-modules:
46+ Paths_calc
47+ autogen-modules:
48+ Paths_calc
49+ hs-source-dirs:
50+ app
51+ ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
52+ build-depends:
53+ base >=4.7 && <5
54+ , calc
55+ , mtl
56+ , scotty
57+ , text
58+ default-language: Haskell2010
59+
60+test-suite calc-test
61+ type: exitcode-stdio-1.0
62+ main-is: Spec.hs
63+ other-modules:
64+ Paths_calc
65+ autogen-modules:
66+ Paths_calc
67+ hs-source-dirs:
68+ test
69+ ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
70+ build-depends:
71+ base >=4.7 && <5
72+ , calc
73+ , mtl
74+ , scotty
75+ , text
76+ default-language: Haskell2010
seminars/calc/package.yamlnew file+62
@@ -0,0 +1,62 @@
1+name: calc
2+version: 0.1.0.0
3+github: "githubuser/calc"
4+license: BSD-3-Clause
5+author: "Author name here"
6+maintainer: "example@example.com"
7+copyright: "2025 Author name here"
8+
9+extra-source-files:
10+- README.md
11+- CHANGELOG.md
12+
13+# Metadata used when publishing your package
14+# synopsis: Short description of your package
15+# category: Web
16+
17+# To avoid duplicated efforts in documentation and dealing with the
18+# complications of embedding Haddock markup inside cabal files, it is
19+# common to point users to the README.md file.
20+description: Please see the README on GitHub at <https://github.com/githubuser/calc#readme>
21+
22+dependencies:
23+- base >= 4.7 && < 5
24+- scotty
25+- text
26+- mtl
27+
28+ghc-options:
29+- -Wall
30+- -Wcompat
31+- -Widentities
32+- -Wincomplete-record-updates
33+- -Wincomplete-uni-patterns
34+- -Wmissing-export-lists
35+- -Wmissing-home-modules
36+- -Wpartial-fields
37+- -Wredundant-constraints
38+
39+library:
40+ source-dirs: src
41+
42+executables:
43+ calc-exe:
44+ main: Main.hs
45+ source-dirs: app
46+ ghc-options:
47+ - -threaded
48+ - -rtsopts
49+ - -with-rtsopts=-N
50+ dependencies:
51+ - calc
52+
53+tests:
54+ calc-test:
55+ main: Spec.hs
56+ source-dirs: test
57+ ghc-options:
58+ - -threaded
59+ - -rtsopts
60+ - -with-rtsopts=-N
61+ dependencies:
62+ - calc
seminars/calc/src/Lib.hsnew file+27
@@ -0,0 +1,27 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE ScopedTypeVariables #-}
3+
4+module Lib
5+ ( server
6+ ) where
7+
8+import Web.Scotty
9+import Data.IORef
10+import qualified Data.Text.Lazy
11+import Control.Monad.Trans
12+
13+server :: IO ()
14+server = do
15+ result <- newIORef 0
16+ scotty 3000 $ do
17+ get "/:word" $ do
18+ beam <- pathParam "word"
19+ html $ mconcat ["<h1>Scotty, ", beam, " me up!</h1>"]
20+ post "/add/:number" $ do
21+ number :: Int <- pathParam "number"
22+ result <- lift $ atomicModifyIORef result (\x -> (x + number, x + number))
23+ -- modifyIORef :: IORef a -> (a -> a) -> IO ()
24+ -- atomicModifyIORef :: IORef a -> (a -> (a, b)) -> IO b
25+ text $ Data.Text.Lazy.pack $ show result
26+
27+-- pure :: a -> ActionT IO a
seminars/calc/stack.yamlnew file+71
@@ -0,0 +1,71 @@
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+# 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+# snapshot: lts-22.28
12+# snapshot: nightly-2024-07-05
13+# snapshot: ghc-9.6.6
14+#
15+# The location of a snapshot can be provided as a file or url. Stack assumes
16+# a snapshot provided as a file might change, whereas a url resource does not.
17+#
18+# snapshot: ./custom-snapshot.yaml
19+# snapshot: https://example.com/snapshots/2024-01-01.yaml
20+snapshot: nightly-2024-10-11
21+
22+nix:
23+ enable: true
24+ packages:
25+ - zlib
26+
27+# User packages to be built.
28+# Various formats can be used as shown in the example below.
29+#
30+# packages:
31+# - some-directory
32+# - https://example.com/foo/bar/baz-0.0.2.tar.gz
33+# subdirs:
34+# - auto-update
35+# - wai
36+packages:
37+- .
38+# Dependency packages to be pulled from upstream that are not in the snapshot.
39+# These entries can reference officially published versions as well as
40+# forks / in-progress versions pinned to a git hash. For example:
41+#
42+# extra-deps:
43+# - acme-missiles-0.3
44+# - git: https://github.com/commercialhaskell/stack.git
45+# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
46+#
47+# extra-deps: []
48+
49+# Override default flag values for project packages and extra-deps
50+# flags: {}
51+
52+# Extra package databases containing global packages
53+# extra-package-dbs: []
54+
55+# Control whether we use the GHC we find on the path
56+# system-ghc: true
57+#
58+# Require a specific version of Stack, using version ranges
59+# require-stack-version: -any # Default
60+# require-stack-version: ">=3.1"
61+#
62+# Override the architecture used by Stack, especially useful on Windows
63+# arch: i386
64+# arch: x86_64
65+#
66+# Extra directories used by Stack for building
67+# extra-include-dirs: [/path/to/dir]
68+# extra-lib-dirs: [/path/to/dir]
69+#
70+# Allow a newer minor version of GHC than the snapshot specifies
71+# compiler-check: newer-minor
seminars/calc/test/Spec.hsnew file+2
@@ -0,0 +1,2 @@
1+main :: IO ()
2+main = putStrLn "Test suite not yet implemented"