on master help sign in
Add something like Haskell's "error" function.

It is in Debug.Error. It prints the source location that it was called from and a user-supplied message before terminating the program. Fixes #1692.

commitaaaad69222312f2289d35a777fc3cf69a2fad3ac authorDavid Raymond Christiansen <david@davidchristiansen.dk> dateFri 28 Nov 2014, 09:43 (12 years ago) parentf1e161d
2 files changed+21−1
libs/base/Debug/Error.idr+20 libs/base/base.ipkg+1−1
libs/base/Debug/Error.idrnew file+20
@@ -0,0 +1,20 @@
1+module Debug.Error
2+
3+import Language.Reflection
4+import System
5+
6+||| Terminate the program after printing a user-specified error message.
7+|||
8+||| @ loc The source location to display for the error
9+||| @ message The error to print
10+partial
11+error : {default tactics {sourceLocation} loc : SourceLocation} ->
12+ (message : String) ->
13+ a
14+error {loc = FileLoc filename (line, col) _} message =
15+ believe_me . unsafePerformIO $
16+ do let place = filename ++ " line " ++ show line ++ " column " ++ show col
17+ let message' = place ++ ": " ++ message
18+ putStrLn message'
19+ exit 1
20+
libs/base/base.ipkg+1−1
@@ -4,7 +4,7 @@ opts = "--nobasepkgs --total -i ../prelude"
44modules = System,
55
66 Network.Cgi, Network.Socket,
7− Debug.Trace,
7+ Debug.Error, Debug.Trace,
88
99 System.Info,
1010 System.Concurrency.Raw, System.Concurrency.Process,