Skip to content

Commit c46462f

Browse files
committed
Code cleanup. Add license file.
1 parent 9d3ee48 commit c46462f

File tree

4 files changed

+71
-39
lines changed

4 files changed

+71
-39
lines changed

Diff for: LICENSE

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2020, Tomasz Rybarczyk (aka paluh)
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
* Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Diff for: src/Data/Undefined/NoProblem.purs

+42-34
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
module Data.Undefined.NoProblem where
22

33
import Prelude
4-
5-
import Data.Either (Either)
64
import Data.Eq (class Eq1, eq1)
75
import Data.Maybe (Maybe(..), maybe)
8-
import Data.Tuple (Tuple)
9-
import Effect (Effect)
106
import Foreign (Foreign)
117
import Foreign (isUndefined) as Foreign
12-
import Prim.RowList (class RowToList, Cons, Nil, kind RowList)
13-
import Prim.TypeError (class Fail, Above, Beside, Quote, QuoteLabel, Text, kind Doc)
8+
import Prim.TypeError (Above, Beside, Quote, QuoteLabel, Text, kind Doc)
149
import Unsafe.Coerce (unsafeCoerce)
1510

1611
foreign import data OptType Type
12+
1713
instance eqOptEq a Eq (Opt a) where
1814
eq u1 u2 = toMaybe u1 == toMaybe u2
15+
1916
instance eq1OptEq a Eq1 Opt where
2017
eq1 u1 u2 = eq1 (toMaybe u1) (toMaybe u2)
18+
2119
instance ordOptOrd a Ord (Opt a) where
2220
compare u1 u2 = toMaybe u1 `compare` toMaybe u2
21+
2322
instance showOptShow a Show (Opt a) where
2423
show = maybe "undefined" ("Opt " <> _) <<< map show <<< toMaybe
2524

@@ -33,16 +32,20 @@ fromOpt ∷ ∀ a. a → Opt a → a
3332
fromOpt = flip fromOptFlipped
3433

3534
fromOptFlipped a. Opt a a a
36-
fromOptFlipped o default = if isUndefined o
37-
then default
38-
else unsafeCoerce o
35+
fromOptFlipped o default =
36+
if isUndefined o then
37+
default
38+
else
39+
unsafeCoerce o
3940

4041
infixl 9 fromOptFlipped as !
4142

4243
toMaybe a. Opt a Maybe a
43-
toMaybe o = if isUndefined o
44-
then Nothing
45-
else Just (unsafeUnwrap o)
44+
toMaybe o =
45+
if isUndefined o then
46+
Nothing
47+
else
48+
Just (unsafeUnwrap o)
4649

4750
isUndefined a. Opt a Boolean
4851
isUndefined undef = Foreign.isUndefined (unsafeCoerce undef Foreign)
@@ -55,45 +58,50 @@ unsafeUnwrap = unsafeCoerce
5558
-- |
5659
-- | It is only to provide nice operator:
5760
-- | (coerce {}) ? _.a ? _.b ? _.c.d ! "default"
58-
pseudoBind :: forall a b . Opt a -> (a -> Opt b) -> Opt b
59-
pseudoBind o f = if isUndefined o
60-
then undefined
61-
else f (unsafeUnwrap o)
61+
pseudoBind :: forall a b. Opt a -> (a -> Opt b) -> Opt b
62+
pseudoBind o f =
63+
if isUndefined o then
64+
undefined
65+
else
66+
f (unsafeUnwrap o)
6267

6368
infixl 9 pseudoBind as ?
6469

6570
-- | Ripped from typelevel-eval
6671
infixr 2 type Beside as <>
72+
6773
infixr 1 type Above as |>
6874

6975
-- | Ripped from record-extra
7076
foreign import kind SList
77+
7178
foreign import data SConsSymbol SList SList
79+
7280
foreign import data SNilSList
7381

7482
infixr 6 type SCons as :::
7583

7684
class RenderPath (pathSList) (renderDoc) | path render
85+
7786
instance renderPathEndRenderPath SNil (Text "")
7887
else instance renderPathLastRenderPath (n ::: SNil) (QuoteLabel n)
79-
else instance renderPathSegment
80-
(RenderPath tail p )
81-
RenderPath (segment ::: tail) (p <> Text "." <> QuoteLabel segment)
88+
else instance renderPathSegment
89+
(RenderPath tail p)
90+
RenderPath (segment ::: tail) (p <> Text "." <> QuoteLabel segment)
8291

8392
class TypeMismatchErr given expected (pathSList) (msgDoc) | path expected given msg
84-
instance typeMismatchErr
85-
∷ (RenderPath p p')
86-
TypeMismatchErr given expected p
87-
( Text "Type mismatch on the path: { " <> p' <> Text " }. Expecting"
88-
|> Text ""
89-
|> Quote expected
90-
|> Text ""
91-
|> Text "but got"
92-
|> Text ""
93-
|> Quote given
94-
|> Text ""
95-
|> Text "If one of the types above is a type variable like `t2` or `r172`"
96-
|> Text "it probably means that you should provide type annotation to some"
97-
|> Text "parts of your value (like `[] ∷ Array Int` or `Nothing ∷ Maybe String`)"
98-
)
9993

94+
instance typeMismatchErr
95+
(RenderPath p p')
96+
TypeMismatchErr given expected p ( Text "Type mismatch on the path: { " <> p' <> Text " }. Expecting"
97+
|> Text ""
98+
|> Quote expected
99+
|> Text ""
100+
|> Text "but got"
101+
|> Text ""
102+
|> Quote given
103+
|> Text ""
104+
|> Text "If one of the types above is a type variable like `t2` or `r172`"
105+
|> Text "it probably means that you should provide type annotation to some"
106+
|> Text "parts of your value (like `[] ∷ Array Int` or `Nothing ∷ Maybe String`)"
107+
)

Diff for: src/Data/Undefined/NoProblem/Closed.purs

-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Data.Either (Either)
44
import Data.Maybe (Maybe)
55
import Data.Tuple (Tuple)
66
import Data.Undefined.NoProblem (class RenderPath, type (:::), type (<>), type (|>), Opt, SNil, kind SList)
7-
-- import Data.Variant (Variant)
87
import Effect (Effect)
98
import Prim.RowList (class RowToList, Cons, Nil, kind RowList)
109
import Prim.TypeError (class Fail, QuoteLabel, Text)
@@ -94,9 +93,6 @@ else instance coercePropTuple ∷
9493
, CoerceProp a2 b2 ("Tuple.snd" ::: p)
9594
)
9695
CoerceProp (Tuple a1 a2) (Tuple b1 b2) p
97-
-- else instance coercePropVariant ∷
98-
-- (RowToList e el, RowToList g gl, CoerceProps gl el p) ⇒
99-
-- CoerceProp (Variant g) (Variant e) p
10096
else instance coercePropEffect
10197
(CoerceProp a b ("Effect" ::: p))
10298
CoerceProp (Effect a) (Effect b) p

Diff for: test/Main.purs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module Test.Main where
22

33
import Prelude
4-
54
import Effect (Effect)
65
import Test.README (closedCoercePolymorphicArray, openCoerceNonPolymorphicArray, optValues, recordCoerce) as Test.README
76

0 commit comments

Comments
 (0)