Skip to content

Instantly share code, notes, and snippets.

View ppetr's full-sized avatar
🤞
I may be slow to respond.

Petr ppetr

🤞
I may be slow to respond.
View GitHub Profile
@ppetr
ppetr / Main.dump-simpl
Created October 28, 2012 05:23
Is it possible to make GHC optimize (deforest) generic functions such as catamorphisms?
Result size = 325
Main.$fFunctorTreeT_$cfmap
:: forall a_ajJ b_ajK.
(a_ajJ -> b_ajK) -> Main.TreeT a_ajJ -> Main.TreeT b_ajK
[GblId,
Arity=2,
Caf=NoCafRefs,
Str=DmdType LS,
Unf=Unf{Src=<vanilla>, TopLvl=True, Arity=2, Value=True,
@ppetr
ppetr / CoerceUsingUnsafe.hs
Created September 10, 2012 19:44
An example how to convert any type to any other using Haskell's unsafePerformIO
module CoerceUsingUnsafe where
import Data.IORef
import System.IO.Unsafe (unsafePerformIO)
import Data.Word
{- The trick behind this function is in the `test` experession.
When we create a new mutable variable in the IO monad,
it has a side effect of creating it somewhere in the memory.
@ppetr
ppetr / Pause.lhs
Created August 31, 2012 13:01
An implementation of a Pause monad from http://stackoverflow.com/q/10236953/1333025
http://stackoverflow.com/q/10236953/1333025
I quite enjoyed this exercise. I tried to do it without looking at the answers,
and it was worth it. It took me considerable time, but the result is
surprisingly close to two of the other answers, as well as to
[monad-coroutine](http://hackage.haskell.org/package/monad-coroutine) library.
So I guess this is somewhat natural solution to this problem. Without this
exercise, I wouldn't understand how _monad-coroutine_ really works.
To add some additional value, I'll explain the steps that eventually led me to