Skip to content

Instantly share code, notes, and snippets.

@deech
deech / table-sort compile output -v3
Last active August 29, 2015 14:12
table-sort compile output -v3
[1 of 1] Compiling Main ( src/Examples/table-sort.hs, dist/build/table-sort/table-sort-tmp/Main.o )
*** Parser:
*** Renamer/typechecker:
*** Desugar:
Result size of Desugar (after optimization)
= {terms: 24,591, types: 551,63, coercions: 5,5}
src/Examples/table-sort.hs:89:17: Warning:
This binding for `isSelected' shadows the existing binding
imported from `Graphics.UI.FLTK.LowLevel.FLTKHS' at src/Examples/table-sort.hs:7:1-39
@deech
deech / Subtyping.hs
Last active September 22, 2015 06:23
Subtyping, OO-Style
{-# LANGUAGE GADTs, MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, UndecidableInstances, FlexibleContexts, OverlappingInstances, ScopedTypeVariables #-}
-- The goal of the code below is to emulate OO method dispatch.
--
-- The use-case is binding to a C++ GUI framework that is heavily OO and
-- providing the user with a familiar experience.
--
-- This scheme sketched out below emulates not only OO style method dispatch
-- but also allows users to "sub-class", "override" and even arbitrarily
-- change the type signature of overridden methods, all without touching the
-- original library code.
{-# LANGUAGE TypeFamilies, UndecidableInstances #-}
data A = A
data B = B
data Found a = Found a
data NotFound = NotFound
type family F x
type instance F A = Found (Int -> Int)
type family FindF x where
FindF f = CheckFoundF (F f)
type family CheckFoundF res where
kill ((x:y:ys), zs) = kill (ys, zs ++ [x])
kill ([x], (_:zs)) = kill (zs, [x])
kill ([x], []) = x
kill ([], zs) = kill (zs, [])
run = kill ([1..100], [])
> run
73
--- StackTraced.hs
module StackTraced
(StackTraced.head)
where
import Debug.Trace
import Control.Exception
import System.IO.Unsafe
stackTrace ::SomeException -> IO a
stackTrace e = traceStack (show e) $ error "empty head"
head :: [a] -> a
@deech
deech / gist:7697998
Created November 28, 2013 20:57
Spidermonkey Test
>>> var noel = "noël";
undefined
>>> noel.substring(0,3)
"noë"
>>> noel.split("").reverse().join("")
"lëon"
>>> noel.length
4
>>> noel
"noël"
@deech
deech / gist:7697971
Created November 28, 2013 20:54
JavaScript String Test
> var noel = "noël"
> noel
"noël"
> noel.substring(0,3)
"noë"
> noel.split("").reverse().join("")
"lëon"
> noel.length
4
@deech
deech / gist:7697936
Created November 28, 2013 20:49
Elisp String Test
ELISP> (setq *noel* "noël")
"noël"
ELISP> (subseq *noel* 0 3)
"noë"
ELISP> (length *noel*)
4
ELISP> (apply #'string (reverse (string-to-list *noel*)))
"lëon"
@deech
deech / gist:7697831
Created November 28, 2013 20:39
SBCL String Test
* (defparameter *noel* "noël")
*NOEL*
* (subseq *noel* 0 3)
"noë"
* (reverse *noel*)
"lëon"
@deech
deech / gist:7697521
Created November 28, 2013 20:12
Haskell Unicode String Test
Prelude> let noel = "noël"
Prelude> reverse noel
"l\235on"
Prelude> take 3 noel
"no\235"
Prelude> length noel
4