File tree Expand file tree Collapse file tree 6 files changed +60
-6
lines changed Expand file tree Collapse file tree 6 files changed +60
-6
lines changed Original file line number Diff line number Diff line change 1+ ## Module Partial
2+
3+ Some partial helper functions.
4+
5+ #### ` crash `
6+
7+ ``` purescript
8+ crash :: forall a. (Partial) => a
9+ ```
10+
11+ A partial function which crashes on any input with a default message.
12+
13+ #### ` crashWith `
14+
15+ ``` purescript
16+ crashWith :: forall a. (Partial) => String -> a
17+ ```
18+
19+ A partial function which crashes on any input with the specified message.
20+
21+
Original file line number Diff line number Diff line change @@ -10,4 +10,12 @@ unsafePartial :: forall a. (Partial => a) -> a
1010
1111Discharge a partiality constraint, unsafely.
1212
13+ #### ` unsafeCrashWith `
14+
15+ ``` purescript
16+ unsafeCrashWith :: forall a. String -> a
17+ ```
18+
19+ A function which crashes with the specified error message.
20+
1321
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+ // module Partial
4+
5+ exports . crashWith = function ( ) {
6+ return function ( msg ) {
7+ throw new Error ( msg ) ;
8+ } ;
9+ } ;
Original file line number Diff line number Diff line change 1+ -- | Some partial helper functions.
2+ module Partial
3+ ( crash
4+ , crashWith
5+ ) where
6+
7+ -- | A partial function which crashes on any input with a default message.
8+ crash :: forall a . Partial => a
9+ crash = crashWith " Partial.crash: partial function"
10+
11+ -- | A partial function which crashes on any input with the specified message.
12+ foreign import crashWith :: forall a . Partial => String -> a
Original file line number Diff line number Diff line change 11-- | Utilities for working with partial functions.
22module Partial.Unsafe
33 ( unsafePartial
4+ , unsafeCrashWith
45 ) where
56
67-- | Discharge a partiality constraint, unsafely.
78foreign import unsafePartial :: forall a . (Partial => a ) -> a
9+
10+ -- | A function which crashes with the specified error message.
11+ unsafeCrashWith :: forall a . String -> a
12+ unsafeCrashWith msg = unsafePartial (Partial .crashWith msg)
Original file line number Diff line number Diff line change 11module Test.Main where
22
3- data X = X | Y
3+ f :: Partial => Int -> Int
4+ f 0 = 0
5+ f _ = Partial .crashWith " f: partial function"
46
5- f :: Partial => X -> X
6- f X = X
7-
8- safely :: X
9- safely = Partial.Unsafe .unsafePartial (f X )
7+ safely :: Int
8+ safely = Partial.Unsafe .unsafePartial (f 0 )
109
1110main :: forall a . a -> { }
1211main _ = {}
You can’t perform that action at this time.
0 commit comments