Skip to content

Commit aedff90

Browse files
committed
new repo
0 parents  commit aedff90

13 files changed

+556
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
result
2+
result-*

ascii-group/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
result
2+
result-*

ascii-group/ascii-group.cabal

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
cabal-version: 3.0
2+
3+
name: ascii-group
4+
version: 1.0.0.14
5+
synopsis: ASCII character groups
6+
category: Data, Text
7+
8+
description:
9+
This package defines a @Group@ type that describes
10+
the two varieties of ASCII character, and provides
11+
some functions for classifying characters by group.
12+
13+
license: Apache-2.0
14+
license-file: license.txt
15+
16+
author: Chris Martin
17+
maintainer: Chris Martin, Julie Moronuki
18+
19+
homepage: https://github.com/typeclasses-group/ascii
20+
bug-Reports: https://github.com/typeclasses/ascii-group/issues
21+
22+
extra-doc-files: *.md
23+
24+
source-repository head
25+
type: git
26+
location: git://github.com/typeclasses/ascii-group.git
27+
28+
common base
29+
default-language: Haskell2010
30+
ghc-options: -Wall
31+
32+
default-extensions:
33+
NoImplicitPrelude
34+
35+
build-depends:
36+
ascii-char ^>= 1.0
37+
, base ^>= 4.14 || ^>= 4.15 || ^>= 4.16 || ^>= 4.17
38+
39+
library
40+
import: base
41+
hs-source-dirs: library
42+
43+
default-extensions:
44+
DeriveAnyClass
45+
DeriveDataTypeable
46+
DeriveGeneric
47+
DerivingStrategies
48+
StandaloneDeriving
49+
50+
build-depends:
51+
hashable ^>= 1.3.5 || ^>= 1.4
52+
53+
exposed-modules:
54+
ASCII.Group
55+
56+
test-suite test-ascii-group
57+
import: base
58+
type: exitcode-stdio-1.0
59+
hs-source-dirs: test
60+
main-is: Main.hs
61+
62+
build-depends:
63+
ascii-group
64+
, hedgehog ^>= 1.0.5 || ^>= 1.1 || ^>= 1.2
65+
66+
default-extensions:
67+
OverloadedStrings
68+
QuasiQuotes
69+
TemplateHaskell

ascii-group/changelog.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
### 1.0.0.14 (2022-12-27)
2+
3+
Metadata changes only
4+
5+
### 1.0.0.13 (2022-10-04)
6+
7+
Drop support for base 4.11 (GHC 8.4) and base 4.12 (GHC 8.6)
8+
9+
### 1.0.0.12 (2022-03-22)
10+
11+
Switch test-suite over to `hedgehog`
12+
13+
### 1.0.0.10 (2022-01-09)
14+
15+
Support GHC 9.2
16+
17+
### 1.0.0.8 (2021-11-13)
18+
19+
Support hashable 1.4
20+
21+
### 1.0.0.6 (2021-09-26)
22+
23+
Add a test suite
24+
25+
### 1.0.0.4 (2021-02-10)
26+
27+
Support GHC 9.0
28+
29+
### 1.0.0.2 (2020-05-18)
30+
31+
Support GHC 8.10
32+
33+
### 1.0.0.0 (2020-05-05)
34+
35+
Initial release

ascii-group/library/ASCII/Group.hs

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{- |
2+
3+
ASCII characters are broadly categorized into two groups: /control codes/ and /printable characters/.
4+
5+
-}
6+
7+
module ASCII.Group
8+
(
9+
{- * The @Group@ type -} Group (..),
10+
{- * Functions -} charGroup, inGroup
11+
{- * Notes -} {- $notes -}
12+
)
13+
where
14+
15+
import ASCII.Char (Char)
16+
import Data.Bool (Bool)
17+
import Data.Data (Data)
18+
import Data.Eq (Eq, (==))
19+
import Data.Hashable (Hashable)
20+
import Data.Ord (Ord, (<))
21+
import GHC.Generics (Generic)
22+
import Prelude (Bounded, Enum)
23+
import Text.Show (Show)
24+
25+
import qualified ASCII.Char as Char
26+
27+
data Group =
28+
Control -- ^ 33 of the ASCII characters are /control codes/. A few of these are still in use, but most are obsolete relics of the early days of computing.
29+
| Printable -- ^ 95 of the ASCII characters are /printable characters/ such as letters and numbers, mostly corresponding to the keys on an American English keyboard.
30+
31+
deriving stock instance Eq Group
32+
33+
deriving stock instance Ord Group
34+
35+
deriving stock instance Enum Group
36+
37+
deriving stock instance Bounded Group
38+
39+
deriving stock instance Show Group
40+
41+
deriving stock instance Data Group
42+
43+
deriving stock instance Generic Group
44+
45+
deriving anyclass instance Hashable Group
46+
47+
{- | Determine which group a particular character belongs to.
48+
49+
>>> map charGroup [CapitalLetterA,EndOfTransmission]
50+
[Printable,Control]
51+
52+
-}
53+
54+
charGroup :: Char -> Group
55+
charGroup x =
56+
case x of
57+
_ | (x < Char.Space) -> Control
58+
Char.Delete -> Control
59+
_ -> Printable
60+
61+
{- | Test whether a character belongs to a particular group.
62+
63+
>>> inGroup Printable EndOfTransmission
64+
False
65+
66+
>>> inGroup Control EndOfTransmission
67+
True
68+
69+
-}
70+
71+
inGroup :: Group -> Char -> Bool
72+
inGroup g x = charGroup x == g
73+
74+
{- $notes
75+
76+
Space is a printable character (perhaps surprisingly, given that it is invisible).
77+
78+
>>> charGroup Space
79+
Printable
80+
81+
Tab is a control code (perhaps surprisingly, given that space is a printable character).
82+
83+
>>> charGroup HorizontalTab
84+
Control
85+
86+
A few examples of printable characters:
87+
88+
>>> all (inGroup Printable) [CapitalLetterA,SmallLetterZ,Digit4,Tilde]
89+
True
90+
91+
A few examples of control characters:
92+
93+
>>> all (inGroup Control) [Null,Substitute,UnitSeparator,Delete]
94+
True
95+
96+
There are 33 control codes.
97+
98+
>>> length (filter (inGroup Control) allCharacters)
99+
33
100+
101+
There are 95 printable characters.
102+
103+
>>> length (filter (inGroup Printable) allCharacters)
104+
95
105+
106+
-}

ascii-group/license.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2021 Mission Valley Software LLC
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

ascii-group/readme.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This package defines a `Group` type that describes the two varieties of ASCII
2+
character, and provides some functions for classifying characters by group.

ascii-group/test/Main.hs

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
module Main (main) where
2+
3+
import ASCII.Group
4+
5+
import ASCII.Char (Char (..), allCharacters)
6+
7+
import Control.Monad (Monad (..))
8+
import Data.Bool (not)
9+
import Data.Foldable (all)
10+
import Data.Function (($))
11+
import Data.List (filter, length)
12+
import System.IO (IO)
13+
import Control.Monad (when)
14+
import System.Exit (exitFailure)
15+
16+
import Hedgehog (Property, assert, checkParallel, discover, property,
17+
withTests, (===))
18+
19+
main :: IO ()
20+
main = checkParallel $$(discover) >>= \ok -> when (not ok) exitFailure
21+
22+
prop_letter :: Property
23+
prop_letter = withTests 1 $ property $
24+
charGroup CapitalLetterA === Printable
25+
26+
prop_control :: Property
27+
prop_control = withTests 1 $ property $
28+
charGroup EndOfTransmission === Control
29+
30+
prop_not_printable :: Property
31+
prop_not_printable = withTests 1 $ property $
32+
assert $ not $ inGroup Printable EndOfTransmission
33+
34+
prop_is_control :: Property
35+
prop_is_control = withTests 1 $ property $
36+
assert $ inGroup Control EndOfTransmission
37+
38+
-- It is perhaps surprising that space is considered a
39+
-- "printable" character, since it does not visibly appear.
40+
prop_space_is_printable :: Property
41+
prop_space_is_printable = withTests 1 $ property $
42+
charGroup Space === Printable
43+
44+
-- It is perhaps surprising that horizontal tab is not
45+
-- in the same category as space.
46+
prop_horizontal_tab_is_control :: Property
47+
prop_horizontal_tab_is_control = withTests 1 $ property $
48+
charGroup HorizontalTab === Control
49+
50+
prop_various_printables :: Property
51+
prop_various_printables = withTests 1 $ property $
52+
assert $ all (inGroup Printable) [CapitalLetterA, SmallLetterZ, Digit4, Tilde]
53+
54+
prop_various_controls :: Property
55+
prop_various_controls = withTests 1 $ property $
56+
assert $ all (inGroup Control) [Null, Substitute, UnitSeparator, Delete]
57+
58+
prop_count_printables :: Property
59+
prop_count_printables = withTests 1 $ property $
60+
length (filter (inGroup Printable) allCharacters) === 95
61+
62+
prop_count_controls :: Property
63+
prop_count_controls = withTests 1 $ property $
64+
length (filter (inGroup Control) allCharacters) === 33

cabal.project

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: ascii-group

default.nix

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
let
2+
3+
sources = import ./nix/sources.nix;
4+
nixos-22-05 = import sources."nixos-22.05" {};
5+
nixos-22-11 = import sources."nixos-22.11" {};
6+
inherit (nixos-22-11) haskell lib symlinkJoin;
7+
inherit (lib) fold composeExtensions concatMap attrValues;
8+
9+
combineOverrides = old:
10+
fold composeExtensions (old.overrides or (_: _: { }));
11+
12+
sourceOverrides = haskell.lib.packageSourceOverrides {
13+
ascii-group = ./ascii-group;
14+
};
15+
16+
ghc."8.10" = nixos-22-05.haskell.packages.ghc8107.override (old: {
17+
overrides = combineOverrides old [ sourceOverrides ];
18+
});
19+
20+
ghc."9.0" = nixos-22-11.haskell.packages.ghc90.override (old: {
21+
overrides = combineOverrides old [ sourceOverrides ];
22+
});
23+
24+
ghc."9.2" = nixos-22-11.haskell.packages.ghc92.override (old: {
25+
overrides = combineOverrides old [ sourceOverrides ];
26+
});
27+
28+
ghc."9.4" = nixos-22-11.haskell.packages.ghc94.override (old: {
29+
overrides = combineOverrides old [ sourceOverrides ];
30+
});
31+
32+
in
33+
34+
symlinkJoin {
35+
name = "ascii-group";
36+
paths = concatMap (x: [x.ascii-group]) (attrValues ghc);
37+
} // {
38+
inherit ghc;
39+
pkgs = nixos-22-11;
40+
}

nix/sources.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"nixos-22.05": {
3+
"branch": "nixos-22.05",
4+
"description": "Nix Packages collection",
5+
"homepage": "",
6+
"owner": "NixOS",
7+
"repo": "nixpkgs",
8+
"rev": "5cfefb9600de34ce9b8015be80948e5ce7458816",
9+
"sha256": "14vwma7lvx0vmq1gk2fp1f6k9s0009awb58z0dlv00rxzyyw02rc",
10+
"type": "tarball",
11+
"url": "https://github.com/NixOS/nixpkgs/archive/5cfefb9600de34ce9b8015be80948e5ce7458816.tar.gz",
12+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
13+
},
14+
"nixos-22.11": {
15+
"branch": "nixos-22.11",
16+
"description": "Nix Packages collection",
17+
"homepage": "",
18+
"owner": "NixOS",
19+
"repo": "nixpkgs",
20+
"rev": "9898811c658d39b2692d0ab744377e02fd85d08b",
21+
"sha256": "0vk147ivb029h5pmg6nb127nvfgmy728nlnzk7x152dl1b68jmx0",
22+
"type": "tarball",
23+
"url": "https://github.com/NixOS/nixpkgs/archive/9898811c658d39b2692d0ab744377e02fd85d08b.tar.gz",
24+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
25+
}
26+
}

0 commit comments

Comments
 (0)