Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import improvements from MTL 2.2 and 2.3 #2

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ormolu formatting
e8d793c8fabcb9b40429c538a42aee103d2d9d05
42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: CI

# Trigger the workflow on push or pull request, but only for the main branch
on:
pull_request:
push:
branches: ["master"]

jobs:
ormolu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: haskell-actions/run-ormolu@v15
native:
name: "Native: GHC ${{ matrix.ghc }} on ${{ matrix.os }}"
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
ghc: ['9.2', '9.4', '9.6', '9.8']
steps:
- name: Checkout base repo
uses: actions/checkout@v4
- name: Set up Haskell
id: setup-haskell
uses: haskell-actions/setup@v2
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: 'latest'
- name: Configure
run: cabal new-configure
- name: Freeze
run: cabal freeze
- name: Cache
uses: actions/cache@v3
with:
path: ${{ steps.setup-haskell.outputs.cabal-store }}
key: ${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze') }}
restore-keys: ${{ runner.os }}-${{ matrix.ghc }}-
- name: Build
run: cabal build all
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist-newstyle
2 changes: 1 addition & 1 deletion demo/demo.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ common base
default-language: GHC2021
ghc-options: -Wall
build-depends:
, base ^>= 4.16 || ^>= 4.17 || ^>= 4.18
, base ^>= 4.16 || ^>= 4.17 || ^>= 4.18 || ^>= 4.19
, monads-tf
default-extensions:
TypeFamilies
Expand Down
19 changes: 11 additions & 8 deletions demo/except-1/Main.hs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import Control.Monad.Except

-- This is the type to represent length calculation error.
data LengthError = EmptyString -- Entered string was empty.
| StringTooLong Int -- A string is longer than 5 characters.
-- Records a length of the string.
| OtherError String -- Other error, stores the problem description.
data LengthError
= EmptyString -- Entered string was empty.
| StringTooLong Int -- A string is longer than 5 characters.
-- Records a length of the string.
| OtherError String -- Other error, stores the problem description.

-- Converts LengthError to a readable message.
instance Show LengthError where
show EmptyString = "The string was empty!"
show (StringTooLong len) =
"The length of the string (" ++ (show len) ++ ") is bigger than 5!"
"The length of the string (" ++ (show len) ++ ") is bigger than 5!"
show (OtherError msg) = msg

-- For our monad type constructor, we use Either LengthError
Expand All @@ -29,9 +30,11 @@ main = do
-- The processing is done in Either monad.
calculateLengthOrFail :: String -> LengthMonad Int
calculateLengthOrFail [] = throwError EmptyString
calculateLengthOrFail s | len > 5 = throwError (StringTooLong len)
| otherwise = return len
where len = length s
calculateLengthOrFail s
| len > 5 = throwError (StringTooLong len)
| otherwise = return len
where
len = length s

-- Prints result of the string length calculation.
reportResult :: LengthMonad Int -> IO ()
Expand Down
1 change: 1 addition & 0 deletions demo/except-2/Main.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Control.Monad.Except
import Control.Monad.IO.Class

-- An IO monad which can return String failure.
-- It is convenient to define the monad type of the combined monad,
Expand Down
8 changes: 4 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
flake-utils.url = "github:numtide/flake-utils";
};

Expand Down
Loading