Skip to content

Commit 10a3ddc

Browse files
authored
Merge pull request #134 from kl0tl/no-monomorphic-proxies
Replace monomorphic proxies by Type.Proxy.Proxy and polymorphic variables
2 parents 176633d + 848b330 commit 10a3ddc

File tree

3 files changed

+189
-189
lines changed

3 files changed

+189
-189
lines changed

src/Data/String/NonEmpty/Internal.purs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Data.Maybe (Maybe(..), fromJust)
88
import Data.Semigroup.Foldable (class Foldable1)
99
import Data.String as String
1010
import Data.String.Pattern (Pattern)
11-
import Data.Symbol (class IsSymbol, SProxy, reflectSymbol)
11+
import Data.Symbol (class IsSymbol, reflectSymbol)
1212
import Prim.TypeError as TE
1313
import Unsafe.Coerce (unsafeCoerce)
1414

@@ -26,10 +26,10 @@ instance showNonEmptyString :: Show NonEmptyString where
2626
-- |
2727
-- | ``` purescript
2828
-- | something :: NonEmptyString
29-
-- | something = nes (SProxy :: SProxy "something")
29+
-- | something = nes (Proxy :: Proxy "something")
3030
-- | ```
3131
class MakeNonEmpty (s :: Symbol) where
32-
nes :: SProxy s -> NonEmptyString
32+
nes :: forall proxy. proxy s -> NonEmptyString
3333

3434
instance makeNonEmptyBad :: TE.Fail (TE.Text "Cannot create an NonEmptyString from an empty Symbol") => MakeNonEmpty "" where
3535
nes _ = NonEmptyString ""

test/Test/Data/String/NonEmpty.purs

+69-69
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import Data.Array.NonEmpty as NEA
66
import Data.Maybe (Maybe(..), fromJust)
77
import Data.String.NonEmpty (Pattern(..), nes)
88
import Data.String.NonEmpty as NES
9-
import Data.Symbol (SProxy(..))
109
import Effect (Effect)
1110
import Effect.Console (log)
1211
import Partial.Unsafe (unsafePartial)
1312
import Test.Assert (assert, assertEqual)
13+
import Type.Proxy (Proxy(..))
1414

1515
testNonEmptyString :: Effect Unit
1616
testNonEmptyString = do
@@ -22,7 +22,7 @@ testNonEmptyString = do
2222
}
2323
assertEqual
2424
{ actual: NES.fromString "hello"
25-
, expected: Just (nes (SProxy :: SProxy "hello"))
25+
, expected: Just (nes (Proxy :: Proxy "hello"))
2626
}
2727

2828
log "toString"
@@ -33,136 +33,136 @@ testNonEmptyString = do
3333

3434
log "appendString"
3535
assertEqual
36-
{ actual: NES.appendString (nes (SProxy :: SProxy "Hello")) " world"
37-
, expected: nes (SProxy :: SProxy "Hello world")
36+
{ actual: NES.appendString (nes (Proxy :: Proxy "Hello")) " world"
37+
, expected: nes (Proxy :: Proxy "Hello world")
3838
}
3939
assertEqual
40-
{ actual: NES.appendString (nes (SProxy :: SProxy "Hello")) ""
41-
, expected: nes (SProxy :: SProxy "Hello")
40+
{ actual: NES.appendString (nes (Proxy :: Proxy "Hello")) ""
41+
, expected: nes (Proxy :: Proxy "Hello")
4242
}
4343

4444
log "prependString"
4545
assertEqual
46-
{ actual: NES.prependString "be" (nes (SProxy :: SProxy "fore"))
47-
, expected: nes (SProxy :: SProxy "before")
46+
{ actual: NES.prependString "be" (nes (Proxy :: Proxy "fore"))
47+
, expected: nes (Proxy :: Proxy "before")
4848
}
4949
assertEqual
50-
{ actual: NES.prependString "" (nes (SProxy :: SProxy "fore"))
51-
, expected: nes (SProxy :: SProxy "fore")
50+
{ actual: NES.prependString "" (nes (Proxy :: Proxy "fore"))
51+
, expected: nes (Proxy :: Proxy "fore")
5252
}
5353

5454
log "contains"
55-
assert $ NES.contains (Pattern "") (nes (SProxy :: SProxy "abcd"))
56-
assert $ NES.contains (Pattern "bc") (nes (SProxy :: SProxy "abcd"))
57-
assert $ not NES.contains (Pattern "cb") (nes (SProxy :: SProxy "abcd"))
58-
assert $ NES.contains (Pattern "needle") (nes (SProxy :: SProxy "haystack with needle"))
59-
assert $ not NES.contains (Pattern "needle") (nes (SProxy :: SProxy "haystack"))
55+
assert $ NES.contains (Pattern "") (nes (Proxy :: Proxy "abcd"))
56+
assert $ NES.contains (Pattern "bc") (nes (Proxy :: Proxy "abcd"))
57+
assert $ not NES.contains (Pattern "cb") (nes (Proxy :: Proxy "abcd"))
58+
assert $ NES.contains (Pattern "needle") (nes (Proxy :: Proxy "haystack with needle"))
59+
assert $ not NES.contains (Pattern "needle") (nes (Proxy :: Proxy "haystack"))
6060

6161
log "localeCompare"
6262
assertEqual
63-
{ actual: NES.localeCompare (nes (SProxy :: SProxy "a")) (nes (SProxy :: SProxy "a"))
63+
{ actual: NES.localeCompare (nes (Proxy :: Proxy "a")) (nes (Proxy :: Proxy "a"))
6464
, expected: EQ
6565
}
6666
assertEqual
67-
{ actual: NES.localeCompare (nes (SProxy :: SProxy "a")) (nes (SProxy :: SProxy "b"))
67+
{ actual: NES.localeCompare (nes (Proxy :: Proxy "a")) (nes (Proxy :: Proxy "b"))
6868
, expected: LT
6969
}
7070
assertEqual
71-
{ actual: NES.localeCompare (nes (SProxy :: SProxy "b")) (nes (SProxy :: SProxy "a"))
71+
{ actual: NES.localeCompare (nes (Proxy :: Proxy "b")) (nes (Proxy :: Proxy "a"))
7272
, expected: GT
7373
}
7474

7575
log "replace"
7676
assertEqual
77-
{ actual: NES.replace (Pattern "b") (NES.NonEmptyReplacement (nes (SProxy :: SProxy "!"))) (nes (SProxy :: SProxy "abc"))
78-
, expected: nes (SProxy :: SProxy "a!c")
77+
{ actual: NES.replace (Pattern "b") (NES.NonEmptyReplacement (nes (Proxy :: Proxy "!"))) (nes (Proxy :: Proxy "abc"))
78+
, expected: nes (Proxy :: Proxy "a!c")
7979
}
8080
assertEqual
81-
{ actual: NES.replace (Pattern "b") (NES.NonEmptyReplacement (nes (SProxy :: SProxy "!"))) (nes (SProxy :: SProxy "abbc"))
82-
, expected: nes (SProxy :: SProxy "a!bc")
81+
{ actual: NES.replace (Pattern "b") (NES.NonEmptyReplacement (nes (Proxy :: Proxy "!"))) (nes (Proxy :: Proxy "abbc"))
82+
, expected: nes (Proxy :: Proxy "a!bc")
8383
}
8484
assertEqual
85-
{ actual: NES.replace (Pattern "d") (NES.NonEmptyReplacement (nes (SProxy :: SProxy "!"))) (nes (SProxy :: SProxy "abc"))
86-
, expected: nes (SProxy :: SProxy "abc")
85+
{ actual: NES.replace (Pattern "d") (NES.NonEmptyReplacement (nes (Proxy :: Proxy "!"))) (nes (Proxy :: Proxy "abc"))
86+
, expected: nes (Proxy :: Proxy "abc")
8787
}
8888

8989
log "replaceAll"
9090
assertEqual
91-
{ actual: NES.replaceAll (Pattern "[b]") (NES.NonEmptyReplacement (nes (SProxy :: SProxy "!"))) (nes (SProxy :: SProxy "a[b]c"))
92-
, expected: nes (SProxy :: SProxy "a!c")
91+
{ actual: NES.replaceAll (Pattern "[b]") (NES.NonEmptyReplacement (nes (Proxy :: Proxy "!"))) (nes (Proxy :: Proxy "a[b]c"))
92+
, expected: nes (Proxy :: Proxy "a!c")
9393
}
9494
assertEqual
95-
{ actual: NES.replaceAll (Pattern "[b]") (NES.NonEmptyReplacement (nes (SProxy :: SProxy "!"))) (nes (SProxy :: SProxy "a[b]c[b]"))
96-
, expected: nes (SProxy :: SProxy "a!c!")
95+
{ actual: NES.replaceAll (Pattern "[b]") (NES.NonEmptyReplacement (nes (Proxy :: Proxy "!"))) (nes (Proxy :: Proxy "a[b]c[b]"))
96+
, expected: nes (Proxy :: Proxy "a!c!")
9797
}
9898
assertEqual
99-
{ actual: NES.replaceAll (Pattern "x") (NES.NonEmptyReplacement (nes (SProxy :: SProxy "!"))) (nes (SProxy :: SProxy "abc"))
100-
, expected: nes (SProxy :: SProxy "abc")
99+
{ actual: NES.replaceAll (Pattern "x") (NES.NonEmptyReplacement (nes (Proxy :: Proxy "!"))) (nes (Proxy :: Proxy "abc"))
100+
, expected: nes (Proxy :: Proxy "abc")
101101
}
102102

103103
log "stripPrefix"
104104
assertEqual
105-
{ actual: NES.stripPrefix (Pattern "") (nes (SProxy :: SProxy "abc"))
106-
, expected: Just (nes (SProxy :: SProxy "abc"))
105+
{ actual: NES.stripPrefix (Pattern "") (nes (Proxy :: Proxy "abc"))
106+
, expected: Just (nes (Proxy :: Proxy "abc"))
107107
}
108108
assertEqual
109-
{ actual: NES.stripPrefix (Pattern "a") (nes (SProxy :: SProxy "abc"))
110-
, expected: Just (nes (SProxy :: SProxy "bc"))
109+
{ actual: NES.stripPrefix (Pattern "a") (nes (Proxy :: Proxy "abc"))
110+
, expected: Just (nes (Proxy :: Proxy "bc"))
111111
}
112112
assertEqual
113-
{ actual: NES.stripPrefix (Pattern "abc") (nes (SProxy :: SProxy "abc"))
113+
{ actual: NES.stripPrefix (Pattern "abc") (nes (Proxy :: Proxy "abc"))
114114
, expected: Nothing
115115
}
116116
assertEqual
117-
{ actual: NES.stripPrefix (Pattern "!") (nes (SProxy :: SProxy "abc"))
117+
{ actual: NES.stripPrefix (Pattern "!") (nes (Proxy :: Proxy "abc"))
118118
, expected: Nothing
119119
}
120120
assertEqual
121-
{ actual: NES.stripPrefix (Pattern "http:") (nes (SProxy :: SProxy "http://purescript.org"))
122-
, expected: Just (nes (SProxy :: SProxy "//purescript.org"))
121+
{ actual: NES.stripPrefix (Pattern "http:") (nes (Proxy :: Proxy "http://purescript.org"))
122+
, expected: Just (nes (Proxy :: Proxy "//purescript.org"))
123123
}
124124
assertEqual
125-
{ actual: NES.stripPrefix (Pattern "http:") (nes (SProxy :: SProxy "https://purescript.org"))
125+
{ actual: NES.stripPrefix (Pattern "http:") (nes (Proxy :: Proxy "https://purescript.org"))
126126
, expected: Nothing
127127
}
128128
assertEqual
129-
{ actual: NES.stripPrefix (Pattern "Hello!") (nes (SProxy :: SProxy "Hello!"))
129+
{ actual: NES.stripPrefix (Pattern "Hello!") (nes (Proxy :: Proxy "Hello!"))
130130
, expected: Nothing
131131
}
132132

133133
log "stripSuffix"
134134
assertEqual
135-
{ actual: NES.stripSuffix (Pattern ".exe") (nes (SProxy :: SProxy "purs.exe"))
136-
, expected: Just (nes (SProxy :: SProxy "purs"))
135+
{ actual: NES.stripSuffix (Pattern ".exe") (nes (Proxy :: Proxy "purs.exe"))
136+
, expected: Just (nes (Proxy :: Proxy "purs"))
137137
}
138138
assertEqual
139-
{ actual: NES.stripSuffix (Pattern ".exe") (nes (SProxy :: SProxy "purs"))
139+
{ actual: NES.stripSuffix (Pattern ".exe") (nes (Proxy :: Proxy "purs"))
140140
, expected: Nothing
141141
}
142142
assertEqual
143-
{ actual: NES.stripSuffix (Pattern "Hello!") (nes (SProxy :: SProxy "Hello!"))
143+
{ actual: NES.stripSuffix (Pattern "Hello!") (nes (Proxy :: Proxy "Hello!"))
144144
, expected: Nothing
145145
}
146146

147147
log "toLower"
148148
assertEqual
149-
{ actual: NES.toLower (nes (SProxy :: SProxy "bAtMaN"))
150-
, expected: nes (SProxy :: SProxy "batman")
149+
{ actual: NES.toLower (nes (Proxy :: Proxy "bAtMaN"))
150+
, expected: nes (Proxy :: Proxy "batman")
151151
}
152152

153153
log "toUpper"
154154
assertEqual
155-
{ actual: NES.toUpper (nes (SProxy :: SProxy "bAtMaN"))
156-
, expected: nes (SProxy :: SProxy "BATMAN")
155+
{ actual: NES.toUpper (nes (Proxy :: Proxy "bAtMaN"))
156+
, expected: nes (Proxy :: Proxy "BATMAN")
157157
}
158158

159159
log "trim"
160160
assertEqual
161-
{ actual: NES.trim (nes (SProxy :: SProxy " abc "))
162-
, expected: Just (nes (SProxy :: SProxy "abc"))
161+
{ actual: NES.trim (nes (Proxy :: Proxy " abc "))
162+
, expected: Just (nes (Proxy :: Proxy "abc"))
163163
}
164164
assertEqual
165-
{ actual: NES.trim (nes (SProxy :: SProxy " \n"))
165+
{ actual: NES.trim (nes (Proxy :: Proxy " \n"))
166166
, expected: Nothing
167167
}
168168

@@ -172,48 +172,48 @@ testNonEmptyString = do
172172
, expected: ""
173173
}
174174
assertEqual
175-
{ actual: NES.joinWith "" [nes (SProxy :: SProxy "a"), nes (SProxy :: SProxy "b")]
175+
{ actual: NES.joinWith "" [nes (Proxy :: Proxy "a"), nes (Proxy :: Proxy "b")]
176176
, expected: "ab"
177177
}
178178
assertEqual
179-
{ actual: NES.joinWith "--" [nes (SProxy :: SProxy "a"), nes (SProxy :: SProxy "b"), nes (SProxy :: SProxy "c")]
179+
{ actual: NES.joinWith "--" [nes (Proxy :: Proxy "a"), nes (Proxy :: Proxy "b"), nes (Proxy :: Proxy "c")]
180180
, expected: "a--b--c"
181181
}
182182

183183
log "join1With"
184184
assertEqual
185-
{ actual: NES.join1With "" (nea [nes (SProxy :: SProxy "a"), nes (SProxy :: SProxy "b")])
186-
, expected: nes (SProxy :: SProxy "ab")
185+
{ actual: NES.join1With "" (nea [nes (Proxy :: Proxy "a"), nes (Proxy :: Proxy "b")])
186+
, expected: nes (Proxy :: Proxy "ab")
187187
}
188188
assertEqual
189-
{ actual: NES.join1With "--" (nea [nes (SProxy :: SProxy "a"), nes (SProxy :: SProxy "b"), nes (SProxy :: SProxy "c")])
190-
, expected: nes (SProxy :: SProxy "a--b--c")
189+
{ actual: NES.join1With "--" (nea [nes (Proxy :: Proxy "a"), nes (Proxy :: Proxy "b"), nes (Proxy :: Proxy "c")])
190+
, expected: nes (Proxy :: Proxy "a--b--c")
191191
}
192192
assertEqual
193-
{ actual: NES.join1With ", " (nea [nes (SProxy :: SProxy "apple"), nes (SProxy :: SProxy "banana")])
194-
, expected: nes (SProxy :: SProxy "apple, banana")
193+
{ actual: NES.join1With ", " (nea [nes (Proxy :: Proxy "apple"), nes (Proxy :: Proxy "banana")])
194+
, expected: nes (Proxy :: Proxy "apple, banana")
195195
}
196196
assertEqual
197-
{ actual: NES.join1With "" (nea [nes (SProxy :: SProxy "apple"), nes (SProxy :: SProxy "banana")])
198-
, expected: nes (SProxy :: SProxy "applebanana")
197+
{ actual: NES.join1With "" (nea [nes (Proxy :: Proxy "apple"), nes (Proxy :: Proxy "banana")])
198+
, expected: nes (Proxy :: Proxy "applebanana")
199199
}
200200

201201
log "joinWith1"
202202
assertEqual
203-
{ actual: NES.joinWith1 (nes (SProxy :: SProxy " ")) (nea ["a", "b"])
204-
, expected: nes (SProxy :: SProxy "a b")
203+
{ actual: NES.joinWith1 (nes (Proxy :: Proxy " ")) (nea ["a", "b"])
204+
, expected: nes (Proxy :: Proxy "a b")
205205
}
206206
assertEqual
207-
{ actual: NES.joinWith1 (nes (SProxy :: SProxy "--")) (nea ["a", "b", "c"])
208-
, expected: nes (SProxy :: SProxy "a--b--c")
207+
{ actual: NES.joinWith1 (nes (Proxy :: Proxy "--")) (nea ["a", "b", "c"])
208+
, expected: nes (Proxy :: Proxy "a--b--c")
209209
}
210210
assertEqual
211-
{ actual: NES.joinWith1 (nes (SProxy :: SProxy ", ")) (nea ["apple", "banana"])
212-
, expected: nes (SProxy :: SProxy "apple, banana")
211+
{ actual: NES.joinWith1 (nes (Proxy :: Proxy ", ")) (nea ["apple", "banana"])
212+
, expected: nes (Proxy :: Proxy "apple, banana")
213213
}
214214
assertEqual
215-
{ actual: NES.joinWith1 (nes (SProxy :: SProxy "/")) (nea ["a", "b", "", "c", ""])
216-
, expected: nes (SProxy :: SProxy "a/b//c/")
215+
{ actual: NES.joinWith1 (nes (Proxy :: Proxy "/")) (nea ["a", "b", "", "c", ""])
216+
, expected: nes (Proxy :: Proxy "a/b//c/")
217217
}
218218

219219
nea :: Array ~> NEA.NonEmptyArray

0 commit comments

Comments
 (0)