Skip to content

Instantly share code, notes, and snippets.

darkf

  • Zero page
Block or report user

Report or block darkf

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:19901dd61263f0dd49ec
(define (unify a b)
(cond ((and (pair? a)
(pair? b)) (cons (unify (car a) (car b))
(unify (cdr a) (cdr b))))
((symbol? a) b) ; here i just return b, because a symbol matches anything. a more complex system would have a third argument
; , the environment, that tracks existing bindings for a, and prevents conflicts. then, instead of returning b
; we could update the environment with the binding for a = b, or issue a failure (in kanren language, #u)
((eq? a b) b) ; a and b trivially unify without updating any bindings. here I just return their mutual value
View possum.hs
import Prelude hiding (toInteger)
import Data.List
data Value = StringValue String
| IntegerValue Integer
| NameValue String
| FuncValue [String] AST
| NilValue
deriving Show
View gist:2921431
type nat = Zero | Succ of nat
let rec int_of_nat x =
match x with
| Zero -> 0
| Succ x' -> 1 + int_of_nat x'
let rec nat_of_int x =
match x with
| 0 -> Zero
@washort
washort / tutorial.rst
Created Aug 18, 2012
parsley tutorial
View tutorial.rst

Parsley Tutorial

From Regular Expressions To Grammars

Parsley is a pattern matching and parsing tool for Python programmers.

View Graph.hs
-- | Some functions on directed graphs.
module Language.Coatl.Graph where
-- base
import Data.Maybe
-- containers
import Data.Map (Map)
import qualified Data.Map as M
import Data.Set (Set)
import qualified Data.Set as S
-- mtl
@jameshfisher
jameshfisher / halting_problem_javascript.md
Last active Sep 7, 2017
A proof that the Halting problem is undecidable, using JavaScript and examples
View halting_problem_javascript.md

Having read a few proofs that the halting problem is undecidable, I found that they were quite inaccessible, or that they glossed over important details. To counter this, I've attempted to re-hash the proof using a familiar language, JavaScript, with numerous examples along the way.

This famous proof tells us that there is no general method to determine whether a program will finish running. To illustrate this, we can consider programs as JavaScript function calls, and ask whether it is possible to write a JavaScript function which will tell us

@fiorix
fiorix / tcp-proxy.py
Created Feb 21, 2012
twisted tcp proxy
View tcp-proxy.py
#!/usr/bin/env python
# coding: utf-8
# http://musta.sh/2012-03-04/twisted-tcp-proxy.html
import sys
from twisted.internet import defer
from twisted.internet import protocol
from twisted.internet import reactor
from twisted.python import log
@paf31
paf31 / W.lhs
Last active Feb 18, 2019
Algorithm W
View W.lhs
## Principal type-schemes for functional programs
**Luis Damas and Robin Milner, POPL '82**
> module W where
> import Data.List
> import Data.Maybe
> import Data.Function
@kaeluka
kaeluka / horr.erl
Last active Jul 2, 2019
Global mutable state in erlang.
View horr.erl
-module(horr).
-export([malloc/0, free/1, read/1, write/2, test/0]).
% You can use `malloc` to get a globally sharable, mutable cell of memory.
% A difference to C's `malloc` is that such a cell doesn't have a certain size (you can't overflow)
% Memory is initialised with the atom `null`.
malloc() ->
spawn(fun() -> mem(null) end).
% As processes are not garbage collected, you have to call `free` when you're done with your memory:
@kreed131
kreed131 / C8Client2.hs
Created Jul 22, 2011
Simple TCP client on Haskell
View C8Client2.hs
---
-- kreed131.blogspot.com/2011/07/tcp.html
---
import Network.Socket hiding (send, sendTo, recv, recvFrom)
import Network.Socket.ByteString (send, recv)
import qualified Data.ByteString.Char8 as B8
import System.Environment (getArgs)
You can’t perform that action at this time.