Skip to content

Instantly share code, notes, and snippets.

@pasberth
Created February 11, 2014 07:50
Show Gist options
  • Select an option

  • Save pasberth/8930735 to your computer and use it in GitHub Desktop.

Select an option

Save pasberth/8930735 to your computer and use it in GitHub Desktop.
$ ghc a.hs
$ time ./a
./a  1.51s user 1.67s system 77% cpu 4.082 total
$ ghc b.hs
$ time ./b
./b  1.58s user 1.68s system 78% cpu 4.126 total
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RankNTypes #-}
import Prelude hiding (Maybe(..))
import Control.Monad
type Maybe a
= forall b.
(a -> b) -- Just
-> b -- Nothing
-> b
just :: a -> Maybe a
just x y _ = y x
nothing :: forall a. Maybe a
nothing _ x = x
dat :: Maybe Int
dat = just 42
main :: IO ()
main = do
forM_ [0..1000000] $ const $ do
dat print (return ())
{-# LANGUAGE NoImplicitPrelude #-}
import Prelude hiding (Maybe(..))
import Control.Monad
data Maybe a
= Just a
| Nothing
dat :: Maybe Int
dat = Just 42
main :: IO ()
main = do
forM_ [0..1000000] $ const $ do
case dat of
Just x -> print x
Nothing -> return ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment