Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@HeinrichApfelmus
HeinrichApfelmus / gist:1278515
Created October 11, 2011 16:04
wxHaskell - Minimal example demonstrating "concurrent" event occurrences
import Graphics.UI.WX
main = start $ do
-- create widgets
f <- frame [ text := "Example" ]
b <- button f [ text := "Test" ]
e <- entry f [ text := "1" ]
status <- staticText f [ size := sz 40 20 ]
-- populate initial values
@HeinrichApfelmus
HeinrichApfelmus / gist:1523428
Created December 27, 2011 12:07
Reifying case expressions on lists
{-----------------------------------------------------------------------------
Re: Reifying case expressions [on lists]
A version of ListTo that can handle lazy results.
See http://article.gmane.org/gmane.comp.lang.haskell.cafe/94953
and follow-up discussion.
------------------------------------------------------------------------------}
{-# LANGUAGE GADTs #-}
module ListTo (ListTo, caseOf, interpret, idL, takeL, andL, testId, testTake, testAnd) where
@HeinrichApfelmus
HeinrichApfelmus / gist:1550676
Created January 2, 2012 13:26
Space-efficient, composable list transformers
{-----------------------------------------------------------------------------
Re: Space-efficient, composable list transformers
A version of ListTo
that can handle lazy results and sequential compositon.
See http://article.gmane.org/gmane.comp.lang.haskell.cafe/95027
and follow-up discussion.
------------------------------------------------------------------------------}
{-# LANGUAGE GADTs #-}
@HeinrichApfelmus
HeinrichApfelmus / gist:1838304
Created February 15, 2012 19:22
Strange behavior with stereo panning in hsc3-0.9
import Control.Exception
import qualified Sound.SC3 as SC
-- Haskell version
incorrectPan = withSuperCollider $ do
SC.audition $ SC.out 0 $
0.2* SC.balance2 (osc 220) (osc 220) mod (SC.constant 1)
getChar
where
osc freq = SC.sinOsc SC.AR (SC.constant freq) (SC.constant 0)
@HeinrichApfelmus
HeinrichApfelmus / gist:2187593
Created March 24, 2012 20:42
BIjection between Twan van Laarhoven's Pipe and the data types from Conduit
-- http://www.reddit.com/r/haskell/comments/rbgvz/conduits_vs_pipes_using_void_as_an_input_or/
import Control.Monad
data Pipe m i o r =
NeedInput (i -> Pipe m i o r) (Pipe m () o r)
| HaveOutput (Pipe m i o r) (m ()) o
| Finished (Maybe i) r
| PipeM (m (Pipe m i o r)) (m r)
@HeinrichApfelmus
HeinrichApfelmus / ForkLift.hs
Created June 7, 2012 14:26
Forklift - a pattern for performing monadic actions in a worker thread
-- see also
-- http://apfelmus.nfshost.com/blog/2012/06/07-forklift.html
module ForkLift where
import Control.Concurrent
import Control.Monad
import Control.Monad.IO.Class
import Control.Monad.Trans.State
@HeinrichApfelmus
HeinrichApfelmus / Form.html
Created July 19, 2012 13:42
Problem with 'POST' ajax request and Scotty-0.4.4
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" /></script>
<script type="text/javascript" charset="utf-8">
// onLoad Handler
$(function () {
$('#form').submit( function() {
$.post('/submit', { x : $('#x').val() }, function (result) {
$('#x').val(result);
@HeinrichApfelmus
HeinrichApfelmus / GameLoop.hs
Created October 2, 2012 16:49
Game loop in reactive-banana
{------------------------------------------------------------------------------
reactive-banana
Implementation of an "industry strength" game loop with fixed time step
and variable fps.
See also http://gafferongames.com/game-physics/fix-your-timestep/
-------------------------------------------------------------------------------}
{-# LANGUAGE NoMonomorphismRestriction #-}
module Main where
@HeinrichApfelmus
HeinrichApfelmus / gist:3845711
Created October 6, 2012 18:24
Log for haste-boot (2012-10-06)
peach:~ apfelmus$ haste-boot
Downloading base libs from ekblad.cc
Reading package info from stdin ... done.
Reading package info from stdin ... done.
Reading package info from stdin ... done.
Reading package info from stdin ... done.
Attempting to clone/update: git://github.com/valderman/fursuit.git
Cloning into fursuit...
remote: Counting objects: 134, done.
remote: Compressing objects: 100% (74/74), done.
@HeinrichApfelmus
HeinrichApfelmus / CurrencyConverter.js
Created October 19, 2012 15:09
Program compiled with haste that fails with a JavaScript error
/* Eval
Evaluate the given thunk t into head normal form.
If the "thunk" we get isn't actually a thunk, just return it.
*/
function E(t) {
if(t instanceof Thunk) {
if(t.f) {
t.x = t.f();
t.f = 0;
}