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 diff --git a/src/Partial.js b/src/Partial.js index 7f7618c..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); }; 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..2221d09 100644 --- a/src/Partial/Unsafe.purs +++ b/src/Partial/Unsafe.purs @@ -2,18 +2,22 @@ -- | See the README for more documentation. module Partial.Unsafe ( unsafePartial - , unsafePartialBecause , unsafeCrashWith ) where import Partial (crashWith) --- | Discharge a partiality constraint, unsafely. -foreign import unsafePartial :: forall a. (Partial => a) -> a +-- 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 --- | *deprecated:* use `unsafePartial` instead. -unsafePartialBecause :: forall a. String -> (Partial => a) -> a -unsafePartialBecause _ x = unsafePartial x +-- | Discharge a partiality constraint, unsafely. +unsafePartial :: forall a. (Partial => a) -> a +unsafePartial = _unsafePartial -- | A function which crashes with the specified error message. unsafeCrashWith :: forall a. String -> a 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 _ = {}