From 05257fed605fedbf4e14ecd4a1e5dbe029f8bc97 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 3 Oct 2020 19:28:10 -0700 Subject: [PATCH 1/7] Update tag to v0.14.0-rc2 --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1a24372..4036f44 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,8 @@ node_js: 6 env: - PATH=$HOME/purescript:$PATH install: - - TAG=$(basename $(curl --location --silent --output /dev/null -w %{url_effective} https://github.com/purescript/purescript/releases/latest)) + - TAG=v0.14.0-rc2 + # - TAG=$(basename $(curl --location --silent --output /dev/null -w %{url_effective} https://github.com/purescript/purescript/releases/latest)) - curl --location --output $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz - tar -xvf $HOME/purescript.tar.gz -C $HOME/ - chmod a+x $HOME/purescript From 63be314d9ebe3ae57043616be19fd14ba4fcc471 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sun, 4 Oct 2020 07:02:34 -0700 Subject: [PATCH 2/7] Fix compiler warnings for v0.14.0-rc2 --- src/Partial.js | 2 +- src/Partial.purs | 5 ++++- src/Partial/Unsafe.js | 2 +- src/Partial/Unsafe.purs | 5 ++++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Partial.js b/src/Partial.js index 7f7618c..cc53934 100644 --- a/src/Partial.js +++ b/src/Partial.js @@ -2,7 +2,7 @@ // module Partial -exports.crashWith = function () { +exports._crashWith = function () { return function (msg) { throw new Error(msg); }; diff --git a/src/Partial.purs b/src/Partial.purs index 3cebd8c..22e2b07 100644 --- a/src/Partial.purs +++ b/src/Partial.purs @@ -9,4 +9,7 @@ crash :: forall a. Partial => a crash = crashWith "Partial.crash: partial function" -- | A partial function which crashes on any input with the specified message. -foreign import crashWith :: forall a. Partial => String -> a +crashWith :: forall a. Partial => String -> a +crashWith = _crashWith + +foreign import _crashWith :: forall a. String -> a diff --git a/src/Partial/Unsafe.js b/src/Partial/Unsafe.js index f0be1fd..7ec706e 100644 --- a/src/Partial/Unsafe.js +++ b/src/Partial/Unsafe.js @@ -2,6 +2,6 @@ // module Partial.Unsafe -exports.unsafePartial = function (f) { +exports._unsafePartial = function (f) { return f(); }; diff --git a/src/Partial/Unsafe.purs b/src/Partial/Unsafe.purs index d50ef3c..44e7361 100644 --- a/src/Partial/Unsafe.purs +++ b/src/Partial/Unsafe.purs @@ -9,7 +9,10 @@ module Partial.Unsafe import Partial (crashWith) -- | Discharge a partiality constraint, unsafely. -foreign import unsafePartial :: forall a. (Partial => a) -> a +foreign import _unsafePartial :: forall a b. a -> b + +unsafePartial :: forall a. (Partial => a) -> a +unsafePartial = _unsafePartial -- | *deprecated:* use `unsafePartial` instead. unsafePartialBecause :: forall a. String -> (Partial => a) -> a From e449bfe274d3080c92ec19cdcbf6445563715f7c Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sun, 4 Oct 2020 14:00:04 -0700 Subject: [PATCH 3/7] Remove outher function in _crashWith FFI --- src/Partial.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Partial.js b/src/Partial.js index cc53934..4870111 100644 --- a/src/Partial.js +++ b/src/Partial.js @@ -2,8 +2,6 @@ // module Partial -exports._crashWith = function () { - return function (msg) { - throw new Error(msg); - }; +exports._crashWith = function (msg) { + throw new Error(msg); }; From 7c3d3d10e6e49462a092a92fd2cdce755c9f6a7f Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sun, 4 Oct 2020 14:00:54 -0700 Subject: [PATCH 4/7] Move unsafePartial's original doc comment down to function --- src/Partial/Unsafe.purs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Partial/Unsafe.purs b/src/Partial/Unsafe.purs index 44e7361..f4f7041 100644 --- a/src/Partial/Unsafe.purs +++ b/src/Partial/Unsafe.purs @@ -8,9 +8,9 @@ module Partial.Unsafe import Partial (crashWith) --- | Discharge a partiality constraint, unsafely. foreign import _unsafePartial :: forall a b. a -> b +-- | Discharge a partiality constraint, unsafely. unsafePartial :: forall a. (Partial => a) -> a unsafePartial = _unsafePartial From 0184577a1154299973e8c98be940cc956f6033ac Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sun, 4 Oct 2020 14:03:29 -0700 Subject: [PATCH 5/7] Add note about unsafePartial's FFI and explain its type signature --- src/Partial/Unsafe.purs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Partial/Unsafe.purs b/src/Partial/Unsafe.purs index f4f7041..5fd3218 100644 --- a/src/Partial/Unsafe.purs +++ b/src/Partial/Unsafe.purs @@ -8,6 +8,12 @@ module Partial.Unsafe import Partial (crashWith) +-- Note: this function's type signature is more like +-- `(Unit -> a) -> a`. However, we would need to use +-- `unsafeCoerce` to make this compile, incurring +-- either a dependency or reimplementing it here. +-- Rather than doing that, we'll use a type signature +-- of `a -> b` instead. foreign import _unsafePartial :: forall a b. a -> b -- | Discharge a partiality constraint, unsafely. From 41b701bb1238ed291dae4c6c18574a5f2a56bfc5 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sun, 4 Oct 2020 14:04:01 -0700 Subject: [PATCH 6/7] Remove deprecated `unsafePartialBecause` --- src/Partial/Unsafe.purs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Partial/Unsafe.purs b/src/Partial/Unsafe.purs index 5fd3218..2221d09 100644 --- a/src/Partial/Unsafe.purs +++ b/src/Partial/Unsafe.purs @@ -2,7 +2,6 @@ -- | See the README for more documentation. module Partial.Unsafe ( unsafePartial - , unsafePartialBecause , unsafeCrashWith ) where @@ -20,10 +19,6 @@ foreign import _unsafePartial :: forall a b. a -> b unsafePartial :: forall a. (Partial => a) -> a unsafePartial = _unsafePartial --- | *deprecated:* use `unsafePartial` instead. -unsafePartialBecause :: forall a. String -> (Partial => a) -> a -unsafePartialBecause _ x = unsafePartial x - -- | A function which crashes with the specified error message. unsafeCrashWith :: forall a. String -> a unsafeCrashWith msg = unsafePartial (crashWith msg) From 290ebcb455415430a03741961c00056bde391be1 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 7 Oct 2020 18:48:06 -0700 Subject: [PATCH 7/7] Remove unsafePartialBecause in test code --- test/Main.purs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/Main.purs b/test/Main.purs index 75265da..837e6fb 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -1,7 +1,7 @@ module Test.Main where import Partial (crashWith) -import Partial.Unsafe (unsafePartial, unsafePartialBecause) +import Partial.Unsafe (unsafePartial) f :: Partial => Int -> Int f 0 = 0 @@ -10,8 +10,5 @@ f _ = crashWith "f: partial function" safely :: Int safely = unsafePartial (f 0) -safely2 :: Int -safely2 = unsafePartialBecause "calling f with argument 0 is guaranteed to be safe" (f 0) - main :: forall a. a -> {} main _ = {}