Skip to content

Instantly share code, notes, and snippets.

getOtherSource = "getOtherSource = $\n\ngetSource = replace getOtherSource $ show getOtherSource\n\nmain = putStrLn getSource\n\nreplace = replace' [] where\n replace' acc (x:xs) what = case x of\n '$' -> reverse acc ++ what ++ xs\n _ -> replace' (x:acc) xs what"
getSource = replace getOtherSource $ show getOtherSource
main = putStrLn getSource
replace = replace' [] where
replace' acc (x:xs) what = case x of
'$' -> reverse acc ++ what ++ xs
_ -> replace' (x:acc) xs what
module Problem where
data _≡_ {A : Set} (x : A) : A Set where
refl : x ≡ x
trans : {A : Set}{x y z : A} x ≡ y y ≡ z x ≡ z
trans refl refl = refl
sym : {A : Set}{x y : A} x ≡ y y ≡ x
sym refl = refl
@ddrone
ddrone / TM.hs
Created November 26, 2012 21:47
Turing machine emulator
import Prelude hiding (Either(..))
import Control.Monad (mapM_)
data Direction = Left | Right | Stay
type State = Int
type Letter = Char
type TMFunction = State -> Letter -> (State, Letter, Direction)
data TM = TM
{ delta :: TMFunction,
@ddrone
ddrone / Mult.hs
Created December 11, 2012 00:33
Turing machine emulators and some examples
import Prelude hiding (Either(..))
import Debug.Trace
import Control.Monad (mapM_)
data Direction = Left | Right | Stay
type State = Int
type Letter = Char
blank = ' '
module Main where
import Data.Char
import Data.Word
import Control.Monad
import Control.Monad.State
import System.Environment
data Expr = Var String
| Int Word8
#lang r5rs
(define (append! x y)
(set-cdr! (last-pair x) y)
x)
(define (last-pair x)
(if (null? (cdr x))
x
(last-pair (cdr x))))
data Blob = Blob { blobSize :: int }
type Segment = Int
type Section = Int
data Elf = Elf
{ elfSegments :: [Segment]
, elfSections :: [Section]
, elfBlob :: Blob }
@ddrone
ddrone / dump.simpl
Created January 24, 2013 17:51
Moving average stream fusion GHC core dump
main1
main1 =
\ eta_Xq ->
case lvl2_r1p5 of _ { I# ipv_aJd ->
case lvl1_r1p2 of _ { I# ipv1_aJi ->
letrec {
$wloop_s1fC
$wloop_s1fC =
\ ww_s1f3 ww1_s1f9 ww2_s1fd ->
case ww2_s1fd of wild3_aHE {
module Test where
data _≡_ {A : Set}(x : A) : A → Set where
refl : x ≡ x
data ℕ : Set where
zero : ℕ
succ : ℕ → ℕ
data _≤_ : ℕ → ℕ → Set where
module Linker where
import Control.Monad.State
-- Relocation is either relative relocation (in current code block) or
-- symbol relocation -- a symbol from external library
type Relocation = Either Integer (String, String)
type Symbol = (String, Integer)
-- Whether a block of code is a library or not is stored in the memory