placeholders-0.1: Placeholders for use while developing Haskell code




This module defines placeholders that you can use while coding to allow incomplete code to compile. They work just like undefined, but with improved error messages and compile-time warnings.



 {-# LANGUAGE TemplateHaskell #-}

 import Development.Placeholders

 theUltimateAnswer :: Int
 theUltimateAnswer = $notImplemented

 main = do
     putStrLn "The ultimate answer:"
     print theUltimateAnswer

This will compile with a warning about the unimplemented function:

 $ ghc --make Simple.hs
 Simple.hs:6:21: Unimplemented feature

At runtime, an exception will be thrown when the placeholder is evaluated, indicating the location of the placeholder.

 $ ./Simple
 The ultimate answer:
 Simple: PlaceholderExcption "Unimplemented feature at Simple.hs:6:21"

If compiled with the GHC flag -Werror, the warning will get turned into an error and compilation will fail. -Werror can therefore be used to verify that you haven't left any unintended placeholders behind.


notImplemented :: Q ExpSource

Indicates that this piece of code has not yet been implemented.

$notImplemented = $(placeholder "Unimplemented feature")

todo :: String -> Q ExpSource

Indicates unimplemented code or a known bug with a custom message.

$(todo msg) = $(placeholder ("TODO: " ++ msg))

placeholder :: String -> Q ExpSource

Generates an expression of any type that, if evaluated at runtime will throw a PlaceholderException. It is therefore similar to error, except that the source location is automatically included. Also, a warning is generated at compile time so you won't forget to replace placeholders before packaging your code.

placeholderNoWarning :: String -> Q ExpSource

Similar to placeholder, but does not generate a compiler warning. Use with care!


data PlaceholderException Source

Thrown when attempting to evaluate a placeholder at runtime.