acme-inator-0.1.0.0: Evil inventions in the Tri-State area

Portabilityportable
Stabilityunstable, may self-destruct
MaintainerMark Lentczner <mzero@glyphic.com>
Safe HaskellSafe-Infered

Acme.Inator

Contents

Description

Construction and operation of evil inventions in the Tri-State area. Based on the pioneering work of Dr. Heinz Doofenschmirtz.

Synopsis

Evil Inventions

type EvilInvention a b = (TrappedAgent, a) -> bSource

An EvilInvention is like a normal function a -> b, only used in evil plans. It will only function in the context of a TrappedAgent. See activate for how to turn one one.

inator :: (TrappedAgent, a) -> aSource

Combinator to turn a function into an EvilInvention. Typically applied via the . operator, like so:

    incrementinator :: EvilInvention Int Int
    incrementinator = (+1) . inator

selfDestruct :: EvilInvention a b -> TriStateArea ()Source

Warning: All EvilInventions have a selfDestruct ability. When an EvilInvention self-destructs, all effects of evil plans in the TriStateArea are nullified, as if Nothing ever happened.

Secret Agents

data Agent Source

Agents are secret, and distinguished only by their letter designations.

Constructors

Agent Char 

data TrappedAgent Source

When trapped, an Agent enables an EvilInvention to be activated and then used. The scope of trapping an Agent is strictly delimited. See whileTrapping.

The TriStateArea

data TriStateArea a Source

Activation and operation of an EvilInvention is strictly limited to the TriStateArea. Plans executed in the TriStateArea may fail, causing the whole plan to have no externally visible effect.

activate :: EvilInvention a b -> TriStateArea (a -> TriStateArea b)Source

EvilInventions must be activated before use. The activated machine can then be applied to suitable targets of scorn and dislike. N.B.: Activation and subsequent operation of an EvilInvention can only be performed in the TriStateArea.

 evilPlan :: TriStateArea Int
 evilPlan = do
    zap <- activate incrementinator
    as <- mapM zap [1..37]
    b <- zap 38 -- I never really liked the number 38
    selfDestruct incrementinator
    cs <- mapM zap [39..100]
    return $ sum as + b + sum cs

whileTrapping :: Agent -> TriStateArea a -> Maybe aSource

To execute any plan (evil or otherwise) in the TriStateArea, an Agent must be trapped with this function, and held for the duration of of the plan.

 executeEvilPlan = whileTrapping perryThePlatypus evilPlan

 main :: IO ()
 main = do
     putStrLn $
         case executeEvilPlan of
             Nothing -> "Curse you, Perry the Platypus!"
             Just a -> "Ha ha! I have incremented the TriStateArea to " ++ show a