File: Util.hs

package info (click to toggle)
haskell-cmdargs 0.10.14-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 348 kB
  • ctags: 1
  • sloc: haskell: 2,972; makefile: 3
file content (32 lines) | stat: -rw-r--r-- 916 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{-# LANGUAGE ExistentialQuantification #-}

module System.Console.CmdArgs.Test.Util where

import System.Console.CmdArgs.Explicit
import Data.Maybe
import Data.Typeable


failure :: String -> [(String,String)] -> IO ()
failure x ys = putStr $ unlines $ "" : "" : "FAILURE" : x : [a ++ ": " ++ b | (a,b) <- ys]

success :: IO ()
success = putChar '.'


-- seq used to obtain better program coverage
hpc = seq


-- Demo - wrap a demo up hiding the real type of it
data Demo = forall a . Typeable a => Demo (a -> IO ()) a

runDemo :: Demo -> IO ()
runDemo (Demo f a) = f a

-- Question: Is it possible to do this without the Typeable constraint?
newDemo :: Typeable a => (a -> IO ()) -> Mode a -> Mode Demo
newDemo act = remap (Demo act) (\(Demo f x) -> (coerce x, Demo f . coerce))
    where
        coerce :: (Typeable a, Typeable b) => a -> b
        coerce = fromMaybe (error "Type issue in CmdArgs.coerce") . cast