git.iko.soy/purescript-literals
on main help sign in
LICENSEnew file+21
since splitsnapshots
unifiedsplit
@@ -0,0 +1,21 @@
1+MIT License
2+
3+Copyright (c) 2020 Jan Vincent Liwanag
4+
5+Permission is hereby granted, free of charge, to any person obtaining a copy
6+of this software and associated documentation files (the "Software"), to deal
7+in the Software without restriction, including without limitation the rights
8+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+copies of the Software, and to permit persons to whom the Software is
10+furnished to do so, subject to the following conditions:
11+
12+The above copyright notice and this permission notice shall be included in all
13+copies or substantial portions of the Software.
14+
15+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+SOFTWARE.
bower.jsonnew file+27
@@ -0,0 +1,27 @@
1+{
2+ "name": "purescript-literals",
3+ "license": [
4+ "MIT"
5+ ],
6+ "repository": {
7+ "type": "git",
8+ "url": "https://github.com/rowtype-yoga/purescript-literals.git"
9+ },
10+ "ignore": [
11+ "**/.*",
12+ "node_modules",
13+ "bower_components",
14+ "output"
15+ ],
16+ "dependencies": {
17+ "purescript-assert": "^v6.0.0",
18+ "purescript-effect": "^v4.0.0",
19+ "purescript-integers": "^v6.0.0",
20+ "purescript-maybe": "^v6.0.0",
21+ "purescript-numbers": "^v9.0.0",
22+ "purescript-partial": "^v4.0.0",
23+ "purescript-prelude": "^v6.0.0",
24+ "purescript-typelevel-prelude": "^v7.0.0",
25+ "purescript-unsafe-coerce": "^v6.0.0"
26+ }
27+}
packages.dhall+2−3
@@ -116,10 +116,9 @@ let additions =
116 }
116 }
117-------------------------------
117-------------------------------
118-}
118-}
119−
120−
121let upstream =
119let upstream =
122− https://github.com/purescript/package-sets/releases/download/psc-0.13.4-20191110/packages.dhall sha256:563a7f694e18e6399f7f6d01f5b7e3c3345781655d99945768f48e458feb93a4
120+ https://github.com/purescript/package-sets/releases/download/psc-0.15.2-20220530/packages.dhall
121+ sha256:15dd8041480502850e4043ea2977ed22d6ab3fc24d565211acde6f8c5152a799
123
122
124let overrides = {=}
123let overrides = {=}
125
124
spago.dhall+15−20
@@ -1,22 +1,17 @@
1−{-
2−Welcome to a Spago project!
3−You can edit this file as you like.
4−-}
5−{ name =
1+{ name = "literals"
6− "literal"
2+, license = "MIT"
3+, repository = "https://github.com/rowtype-yoga/purescript-literals.git"
7, dependencies =
4, dependencies =
8− [ "assert"
5+ [ "assert"
9− , "effect"
6+ , "effect"
10− , "console"
11− , "integers"
7+ , "integers"
8+ , "maybe"
12− , "numbers"
9+ , "numbers"
13− , "partial"
10+ , "partial"
14− , "psci-support"
11+ , "prelude"
12+ , "typelevel-prelude"
15− , "unsafe-coerce"
13+ , "unsafe-coerce"
16− , "typelevel-prelude"
17− ]
14+ ]
18−, packages =
19− ./packages.dhall
15+, packages = ./packages.dhall
20−, sources =
21− [ "src/**/*.purs", "test/**/*.purs" ]
16+, sources = [ "src/**/*.purs", "test/**/*.purs" ]
22}
17}
src/Literals.purs−1
@@ -11,4 +11,3 @@ import Literals.Int (class Digit, class Int, class Int', IntLit, intLit) as Int
11import Literals.Literal (Literal, toValue) as Literal
11import Literals.Literal (Literal, toValue) as Literal
12import Literals.Number (class Number, class Number', NumberLit, numberLit) as Number
12import Literals.Number (class Number, class Number', NumberLit, numberLit) as Number
13import Literals.String (StringLit, stringLit) as String
13import Literals.String (StringLit, stringLit) as String
14−
src/Literals/Int.purs+5−4
@@ -6,7 +6,7 @@ module Literals.Int
6 , class Int
6 , class Int
7 , class Int'
7 , class Int'
8 , intLit
8 , intLit
9− , kind IntPart
9+ , IntPart
10 ) where
10 ) where
11
11
12import Prelude
12import Prelude
@@ -17,7 +17,8 @@ import Data.Symbol (class IsSymbol)
17import Literals.Literal (Literal)
17import Literals.Literal (Literal)
18import Partial.Unsafe (unsafePartial)
18import Partial.Unsafe (unsafePartial)
19import Prim.Symbol (class Cons)
19import Prim.Symbol (class Cons)
20−import Type.Prelude (SProxy(..), reflectSymbol)
20+import Type.Prelude (reflectSymbol)
21+import Type.Proxy (Proxy(..))
21import Unsafe.Coerce (unsafeCoerce)
22import Unsafe.Coerce (unsafeCoerce)
22
23
23class Digit (s :: Symbol)
24class Digit (s :: Symbol)
@@ -33,7 +34,7 @@ else instance digit7 :: Digit "7"
33else instance digit8 :: Digit "8"
34else instance digit8 :: Digit "8"
34else instance digit9 :: Digit "9"
35else instance digit9 :: Digit "9"
35
36
36−foreign import kind IntPart
37+data IntPart
37foreign import data Sign :: IntPart
38foreign import data Sign :: IntPart
38foreign import data IntegerPart :: IntPart
39foreign import data IntegerPart :: IntPart
39
40
@@ -50,4 +51,4 @@ else instance digitIntegerPart :: (Digit h, Cons h' t' t, Int' h' t' IntegerPart
50type IntLit sym = Literal Int sym
51type IntLit sym = Literal Int sym
51
52
52intLit :: forall sym. IsSymbol sym => Int sym => IntLit sym
53intLit :: forall sym. IsSymbol sym => Int sym => IntLit sym
53−intLit = unsafeCoerce $ unsafePartial $ fromJust $ fromString $ reflectSymbol (SProxy :: SProxy sym)
54+intLit = unsafeCoerce $ unsafePartial $ fromJust $ fromString $ reflectSymbol (Proxy :: Proxy sym)
src/Literals/Literal.purs+7
@@ -1,8 +1,15 @@
1module Literals.Literal where
1module Literals.Literal where
2
2
3+import Prelude
4+
3import Unsafe.Coerce (unsafeCoerce)
5import Unsafe.Coerce (unsafeCoerce)
4
6
5foreign import data Literal :: Type -> Symbol -> Type
7foreign import data Literal :: Type -> Symbol -> Type
6
8
9+instance literalEq :: Eq (Literal typ sym) where
10+ eq _ _ = true
11+instance literalShow :: Show typ => Show (Literal typ sym) where
12+ show a = "(Literal " <> (show $ toValue a) <> ")"
13+
7toValue :: ∀ s a. Literal a s -> a
14toValue :: ∀ s a. Literal a s -> a
8toValue = unsafeCoerce
15toValue = unsafeCoerce
src/Literals/Null.js+1−1
@@ -1 +1 @@
1−exports.null = null;
1+export _null = null;
src/Literals/Null.purs+14−2
@@ -1,5 +1,17 @@
1−module Literals.Null where
1+module Literals.Null
2+ ( Null
3+ , null
4+ )
5+where
6+
7+import Prelude
2
8
3foreign import data Null :: Type
9foreign import data Null :: Type
4
10
5−foreign import null :: Null
11+foreign import _null :: Null
12+
13+null :: Null
14+null = _null
15+
16+instance showNull :: Show Null where
17+ show _ = "null"
src/Literals/Number.purs+5−6
@@ -5,7 +5,7 @@ module Literals.Number
5 , Sign
5 , Sign
6 , class Number
6 , class Number
7 , class Number'
7 , class Number'
8− , kind NumberPart
8+ , NumberPart
9 , numberLit
9 , numberLit
10 ) where
10 ) where
11
11
@@ -13,19 +13,19 @@ import Prelude
13
13
14import Data.Maybe (fromJust)
14import Data.Maybe (fromJust)
15import Data.Number (fromString)
15import Data.Number (fromString)
16−import Data.Symbol (class IsSymbol, SProxy(..))
16+import Data.Symbol (class IsSymbol)
17import Literals.Int (class Digit)
17import Literals.Int (class Digit)
18import Literals.Literal (Literal)
18import Literals.Literal (Literal)
19import Partial.Unsafe (unsafePartial)
19import Partial.Unsafe (unsafePartial)
20import Prim.Symbol (class Cons)
20import Prim.Symbol (class Cons)
21−import Type.Prelude (reflectSymbol)
21+import Type.Prelude (reflectSymbol, Proxy(..))
22import Unsafe.Coerce (unsafeCoerce)
22import Unsafe.Coerce (unsafeCoerce)
23
23
24class Number (sym :: Symbol)
24class Number (sym :: Symbol)
25
25
26instance numberInstance :: (Number' h t Sign, Cons h t s) => Number s
26instance numberInstance :: (Number' h t Sign, Cons h t s) => Number s
27
27
28−foreign import kind NumberPart
28+data NumberPart
29foreign import data Sign :: NumberPart
29foreign import data Sign :: NumberPart
30foreign import data IntegerPart :: NumberPart
30foreign import data IntegerPart :: NumberPart
31foreign import data FractionalPart :: NumberPart
31foreign import data FractionalPart :: NumberPart
@@ -42,5 +42,4 @@ else instance digitFractionalPart :: (Digit h, Cons h' t' t, Number' h' t' Fract
42type NumberLit sym = Literal Number sym
42type NumberLit sym = Literal Number sym
43
43
44numberLit :: forall sym. IsSymbol sym => Number sym => NumberLit sym
44numberLit :: forall sym. IsSymbol sym => Number sym => NumberLit sym
45−numberLit = unsafeCoerce $ unsafePartial $ fromJust $ fromString $ reflectSymbol (SProxy :: SProxy sym)
45+numberLit = unsafeCoerce $ unsafePartial $ fromJust $ fromString $ reflectSymbol (Proxy :: Proxy sym)
46−
src/Literals/String.purs+3−4
@@ -3,13 +3,12 @@ module Literals.String
3 , StringLit
3 , StringLit
4 ) where
4 ) where
5
5
6−import Data.Symbol (class IsSymbol, SProxy(..), reflectSymbol)
6+import Data.Symbol (class IsSymbol, reflectSymbol)
7+import Type.Proxy (Proxy(..))
7import Literals.Literal (Literal)
8import Literals.Literal (Literal)
8import Unsafe.Coerce (unsafeCoerce)
9import Unsafe.Coerce (unsafeCoerce)
9
10
10type StringLit sym = Literal String sym
11type StringLit sym = Literal String sym
11
12
12stringLit :: forall sym. IsSymbol sym => StringLit sym
13stringLit :: forall sym. IsSymbol sym => StringLit sym
13−stringLit = unsafeCoerce (reflectSymbol (SProxy :: SProxy sym))
14+stringLit = unsafeCoerce (reflectSymbol (Proxy :: Proxy sym))
14−
15−
src/Literals/Undefined.js+1−1
@@ -1 +1 @@
1−exports.undefined = undefined;
1+export const _undefined = undefined;
src/Literals/Undefined.purs+16−2
@@ -1,5 +1,19 @@
1−module Literals.Undefined where
1+module Literals.Undefined
2+ ( Undefined
3+ , undefined
4+ )
5+where
6+
7+import Prelude
2
8
3foreign import data Undefined :: Type
9foreign import data Undefined :: Type
4
10
11+foreign import _undefined :: Undefined
12+
5−foreign import undefined :: Undefined
13+undefined :: Undefined
14+undefined = _undefined
15+
16+instance undefinedEq :: Eq Undefined where
17+ eq _ _ = true
18+instance undefinedShow :: Show Undefined where
19+ show _ = "Undefined"
test/Main.purs+27−3
@@ -4,7 +4,8 @@ import Prelude
4
4
5import Effect (Effect)
5import Effect (Effect)
6import Literals (NumberLit, StringLit, IntLit, intLit, numberLit, stringLit)
6import Literals (NumberLit, StringLit, IntLit, intLit, numberLit, stringLit)
7+import Literals.Undefined (undefined)
7−import Test.Assert (assertEqual)
8+import Test.Assert (assertEqual, assertTrue)
8import Unsafe.Coerce (unsafeCoerce)
9import Unsafe.Coerce (unsafeCoerce)
9
10
10
11
@@ -18,14 +19,37 @@ main = do
18 { actual: unsafeCoerce (numberLit :: NumberLit "8.0")
19 { actual: unsafeCoerce (numberLit :: NumberLit "8.0")
19 , expected: 8.0
20 , expected: 8.0
20 }
21 }
22+ assertEqual
21− assertEqual { actual: unsafeCoerce (numberLit :: NumberLit "-8.0")
23+ { actual: unsafeCoerce (numberLit :: NumberLit "-8.0")
22 , expected: -8.0
24 , expected: -8.0
23 }
25 }
24 assertEqual
26 assertEqual
25 { actual: unsafeCoerce (intLit :: IntLit "8")
27 { actual: unsafeCoerce (intLit :: IntLit "8")
26 , expected: 8
28 , expected: 8
27 }
29 }
30+ assertEqual
28− assertEqual { actual: unsafeCoerce (intLit :: IntLit "-8")
31+ { actual: unsafeCoerce (intLit :: IntLit "-8")
29 , expected: -8
32 , expected: -8
30 }
33 }
31
34
35+ -- Eq instance
36+ assertTrue $ undefined == undefined
37+ assertTrue $ (stringLit :: StringLit "foo") == (stringLit :: StringLit "foo")
38+
39+ -- Show instance
40+ assertEqual
41+ { actual: show (stringLit :: StringLit "foo")
42+ , expected: "(Literal \"foo\")"
43+ }
44+ assertEqual
45+ { actual: show (numberLit :: NumberLit "8.0")
46+ , expected: "(Literal 8.0)"
47+ }
48+ assertEqual
49+ { actual: show (intLit :: IntLit "8")
50+ , expected: "(Literal 8)"
51+ }
52+ assertEqual
53+ { actual: show undefined
54+ , expected: "Undefined"
55+ }