Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions src/Partial.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

// module Partial

exports.crashWith = function () {
return function (msg) {
throw new Error(msg);
};
exports._crashWith = function (msg) {
throw new Error(msg);
};
5 changes: 4 additions & 1 deletion src/Partial.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/Partial/Unsafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

// module Partial.Unsafe

exports.unsafePartial = function (f) {
exports._unsafePartial = function (f) {
return f();
};
16 changes: 10 additions & 6 deletions src/Partial/Unsafe.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions test/Main.purs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 _ = {}