on 577fc17 help sign in
elk/libraries/Debug.elm
46 lines 1.5 kB history raw
1module Debug where
2{-| This library is for investigating bugs or performance problems. It should
3*not* be used in production code.
5@docs log, crash
6-}
8import Native.Debug
9import Native.Error
11{-| Log a tagged value on the developer console, and then return the value.
13 1 + log "number" 1 -- equals 2, logs "number: 1"
14 length (log "start" []) -- equals 0, logs "start: []"
16Notice that `log` is not a pure function! It should *only* be used for
17investigating bugs or performance problems.
18-}
19log : String -> a -> a
20log = Native.Debug.log
22{-| Crash the program with an error message. This is an uncatchable error,
23intended for code that is soon-to-be-implemented. For example, if you are
24working with a large ADT and have partially completed a case expression, it may
25make sense to do this:
27 data Entity = Ship | Fish | Captain | Seagull
29 drawEntity entity =
30 case entity of
31 Ship -> ...
32 Fish -> ...
33 _ -> Debug.crash ("drawEntity not implemented for " ++ show entity ++ " yet!")
35Note that incomplete pattern matches are *very* bad practice! They are one of
36the very few ways to crash an Elm program, and they are completely avoidable.
37Production code should not have incomplete pattern matches!
39**Use this if** you want to do some testing while you are partway through
40writing a function.
42**Do not use this if** you want to do some typical try-catch exception handling.
43Use the `Maybe` or `Either` libraries instead.
44-}
45crash : String -> a
46crash = Native.Error.raise