Inception

import Data.Maybe

data Person = Person { name :: String
                     , idea :: Maybe String } deriving Show

data Plan = Target Person | Dream Plan deriving Show

fischer = Person "Robert Fischer" Nothing

needToGoDeeper :: Person -> Plan
needToGoDeeper = Dream . Dream . Dream . Target

implant :: Plan -> String -> Plan
implant (Target person) idea = Target $ Person (name person) $ Just idea
implant (Dream plan)    idea = Dream $ implant plan idea

inception = (needToGoDeeper fischer) `implant` "Let's split the company!"

--afterwards

extract :: Plan -> Person
extract (Dream plan)    = extract plan
extract (Target person) = person
Vote up this code1
  • dp wiz

    This one actually works!

    • Axel

      of course it does!

      actually that’s the very first haskell programm i wrote, that isn’t part of an academical or book lesson

    • Bernhard Gschaider

      Non-working code is pointless. Not even for David Lynch-movies

      • Axel

        That’s my brother!