Skip to content

Commit 047aeb8

Browse files
committed
Update for B252
1 parent 806a51f commit 047aeb8

File tree

13 files changed

+249
-154
lines changed

13 files changed

+249
-154
lines changed

.github/workflows/main.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: 'Build and Test'
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
build:
8+
name: 'Build and Test'
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout git repository
12+
uses: actions/checkout@v6
13+
14+
- name: Setup Haskell
15+
uses: haskell-actions/setup@v2
16+
with:
17+
ghc-version: '9.6.7'
18+
enable-stack: true
19+
stack-version: 'latest'
20+
21+
- name: Cache ~/.stack
22+
id: cache-stack
23+
uses: actions/cache@v5
24+
with:
25+
path: ~/.stack
26+
key: stack-home-${{ hashFiles('**/package.yaml')}}-${{ hashFiles('**/stack.yaml*') }}
27+
restore-keys: |
28+
stack-home-
29+
30+
- name: Setup Stack
31+
run: |
32+
stack setup
33+
34+
- name: Install dependencies
35+
run: |
36+
stack build --only-dependencies
37+
38+
- name: Build
39+
run: |
40+
stack build
41+
42+
- name: Test
43+
run: |
44+
stack test

.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
image: haskell:8.8.4
1+
image: haskell:9.6.7
22

33
variables:
44
STACK_ROOT: "${CI_PROJECT_DIR}/.stack"

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ Homework to practice advanced work with typeclasses
88
* First, implement instances of `Validable` for each shape type with function `valid` that says if given shape is valid (its attributes are acceptable, i.e., not negative, forming a triangle).
99
* Then, design on your own the `Shape2D` typeclass which is a subclass of `Validable`, define `area` and `circumference` (remove dummy ones). During the design consider using `valid` - for invalid shape, both functions should return zero.
1010
* Finally, implement instances of `Shape2D` for each shape type.
11-
2. *Data.SortedList* = implement all necessary functions to make data type `SortedList` to be an instance of `Semigroup`, `Monoid`, `Functor`, `Applicative`, `Monad`. After applying `(<>)` the resulting list must be sorted. Sadly, `Functor`, `Applicative`, and `Monad` won't allow you to use `Ord` constaint so the result won't be sorted. Implement some sort function if you want to... It is **forbidden** to just delegate to list and use `fromList` and `toList`.
11+
2. *Data.ResultList* = implement all necessary functions to make data type `ResultList` to be an instance of `Semigroup`, `Monoid`, `Functor`, `Applicative`, `Monad` (expectations should be clear from tests).
1212
3. The final (and also the most interesting) task is to implement functions and instances for next data type to represent integers - the `RomanNumeral` (from `Data.RomanNumeral`)! It is a representation of an integer as Roman numeral, for example, `125` is `"CXXV"`.
1313
* The biggest challenge is to implement functions `integral2RomanNumeral` and `romanNumeral2Integral` (related with `pack` and `unpack`). There is something already prepared in `Data.RomanNumeral.Helpers`. Take a look and feel free to edit as you need.
1414
* After having `pack` and `unpack` working, it will be very easy to make instances of `Bounded`, `Eq`, `Ord`, `Num`, `Enum`, and `Integral` (*you might need some more due to dependencies*) for the `RomanNumeral`.
1515

1616
Hints & general requirements:
1717

1818
* You should not hardcode any string or character in `Data.RomanNumeral` - use only those defined in `Data.RomanNumeral.Helpers` or enhance it.
19-
* Being [DRY](https://cs.wikipedia.org/wiki/Don%27t_repeat_yourself) is essential, do not repeat code. Name expressions to reuse then, introduce helper functions.
2019
* Local names (via `where` or `let-in`) in functions should be introduced to make the code more readable. Creating very simple helper functions in module scope is not nice. If you need some complicated functions create separate "private" module.
2120
* Make your code as clean as possible. Prefer pattern matching and syntactic sugar everywhere it is reasonable.
2221
* **You must understand your code completely**!

package.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ version: 0.1.0.0
33
github: "MI-AFP/hw05"
44
license: MIT
55
author: "Marek Suchánek"
6-
maintainer: "marek.suchanek@fit.cvut.cz"
7-
copyright: "2021 Marek Suchánek"
6+
maintainer: "marek.suchanek@cvut.cz"
7+
copyright: "2026 Marek Suchánek"
88

99
extra-source-files:
1010
- README.md

src/Data/ResultList.hs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module Data.ResultList where
2+
3+
import Data.List (sort)
4+
import Data.Semigroup
5+
6+
data ResultList a = Results [a] | Error Int String
7+
deriving (Show, Read, Eq)
8+
9+
-- | Extract results to a list or return error with message
10+
-- TODO
11+
toList :: ResultList a -> [a]
12+
toList = undefined
13+
14+
15+
instance Semigroup (ResultList a) where
16+
-- | Merge two result lists together
17+
-- TODO
18+
(<>) = undefined
19+
20+
instance Monoid (ResultList a) where
21+
-- TODO
22+
mempty = undefined
23+
mappend = (<>)
24+
25+
instance Functor ResultList where
26+
-- | Apply function over sorted list
27+
-- TODO
28+
fmap = undefined
29+
30+
instance Applicative ResultList where
31+
-- TODO
32+
pure = undefined
33+
-- | Apply all functions to elements in result list
34+
-- TODO
35+
(<*>) = undefined
36+
37+
instance Monad ResultList where
38+
-- | Apply on result list if valid and not empty
39+
-- TODO
40+
(>>=) = undefined

src/Data/RomanNumeral.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import Data.Maybe (fromMaybe)
99
-- DO NOT HARDCODE ANY STRINGs/CHARs IN THIS MODULE!
1010
import qualified Data.RomanNumeral.Helpers as Helpers
1111

12-
-- | RomanNumeral type (wrapper) for English numerals
12+
-- | RomanNumeral type (wrapper) for Roman numerals
1313
newtype RomanNumeral = RomanNumeral String
1414
deriving (Show, Read)
1515

16-
-- | Pack Integer into RomanNumeral (English numeral string)
16+
-- | Pack Integer into RomanNumeral (Roman numeral string)
1717
pack :: (Integral a, Show a) => a -> RomanNumeral
1818
pack integral = RomanNumeral $ fromMaybe err (integral2RomanNumeral integral)
1919
where err = error $ Helpers.messageBadIntegral integral
2020

21-
-- | Unpack RomanNumeral (English numeral string) to Integer
21+
-- | Unpack RomanNumeral (Roman numeral string) to Integer
2222
unpack :: RomanNumeral -> Integer
2323
unpack (RomanNumeral numeral) = fromMaybe err (romanNumeral2Integral numeral)
2424
where err = error $ Helpers.messageBadNumeral numeral

src/Data/RomanNumeral/Helpers.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Data.RomanNumeral.Helpers where
33
import Data.Tuple (swap)
44

55
-- these are to help with RomanNumerals, feel free to edit it if needed
6+
-- you don't have to use them at all... but you can
67

78
-- see: http://www.csgnetwork.com/csgromancnv.html
89

src/Data/SortedList.hs

Lines changed: 0 additions & 49 deletions
This file was deleted.

stack.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# resolver:
1616
# name: custom-snapshot
1717
# location: "./custom-snapshot.yaml"
18-
resolver: lts-16.31
18+
resolver: lts-22.44
1919

2020
# User packages to be built.
2121
# Various formats can be used as shown in the example below.
@@ -39,7 +39,7 @@ packages:
3939
- .
4040
# Dependency packages to be pulled from upstream that are not in the resolver
4141
# (e.g., acme-missiles-0.3)
42-
extra-deps: [datetime-0.3.1]
42+
# extra-deps: [datetime-0.3.1]
4343

4444
# Override default flag values for local packages and extra-deps
4545
# flags: {}
@@ -48,7 +48,7 @@ extra-deps: [datetime-0.3.1]
4848
# extra-package-dbs: []
4949

5050
# Control whether we use the GHC we find on the path
51-
# system-ghc: true
51+
system-ghc: true
5252
#
5353
# Require a specific version of stack, using version ranges
5454
# require-stack-version: -any # Default

stack.yaml.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# This file was autogenerated by Stack.
22
# You should not edit this file by hand.
33
# For more information, please see the documentation at:
4-
# https://docs.haskellstack.org/en/stable/lock_files
4+
# https://docs.haskellstack.org/en/stable/topics/lock_files
55

66
packages:
77
- completed:
88
hackage: datetime-0.3.1@sha256:7e275bd0ce7a2f66445bedfa0006abaf4d41af4c2204c3f8004c17eab5480e74,1534
99
pantry-tree:
10-
size: 334
1110
sha256: d41d182c143676464cb1774f0b7777e870ddeaf8b6cd5fee6ff0114997a1f504
11+
size: 334
1212
original:
1313
hackage: datetime-0.3.1
1414
snapshots:
1515
- completed:
16-
size: 534126
17-
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/16/31.yaml
18-
sha256: 637fb77049b25560622a224845b7acfe81a09fdb6a96a3c75997a10b651667f6
19-
original: lts-16.31
16+
sha256: 238fa745b64f91184f9aa518fe04bdde6552533d169b0da5256670df83a0f1a9
17+
size: 721141
18+
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/44.yaml
19+
original: lts-22.44

0 commit comments

Comments
 (0)