Skip to content

Instantly share code, notes, and snippets.

View queertypes's full-sized avatar

Allele Dev queertypes

  • Georgia, USA
View GitHub Profile
@queertypes
queertypes / server.hs
Created April 24, 2014 17:56
Haskell server
-- From This
main :: IO ()
main = withSocketsDo $ do
args <- getArgs
let port = fromIntegral (read $ head args :: Int)
sock <- listenOn $ PortNumber port
putStrLn $ "Listening on " ++ (head args)
sockHandler sock
-- To This
@queertypes
queertypes / EchoServer.hs
Created April 24, 2014 18:15
Complete with error handling
module Main (main) where
import Network
import System.Environment (getArgs)
import System.IO
import Control.Concurrent
import Control.Applicative
addCommand :: Handle -> [String] -> IO ()
addCommand handle (x:y:_) = hPrint handle $ (read x :: Int) + (read y :: Int)
@queertypes
queertypes / init.el
Created May 8, 2014 19:58
Emacs config
;;; package -- summary
;;; Commentary:
;;; Alejandro Cabrera's init.el
;;; Code:
(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/"))
'("marmalade" . "http://marmalade-repo.org/packages/")
(package-initialize)
alejandro@rainbow-generator:~/haskell/ref-caut:[master *=]$ cabal run -- --target-lang c --output schema_c --input examples/atomicObjectBathroomMonitor.scm
Preprocessing executable 'ref-caut' for ref-caut-0.1.0.0...
(specification "bathroom monitor" "0.0.0" 9F28EC11DCB8345E305685813D8F849772BEDA02
(builtin u8 60DBBD40B307AC819FF2A1BF0A7CF7C5D9E41309 1)
(builtin void CBF9E406F24683F7D894BF8F26AD3AC2E246AB6F 0)
(enum status 1 1 u8 8F9BE19357D113F37695FDFD8A646BD9228EBDE4
(field open void 0)
(field closed void 1))
(struct aoBathrooms 2 2 23B339D11E709BD1326D9CB8490D64E2CC742FB1
(field upstairs status 0)
@queertypes
queertypes / recurse.md
Created September 17, 2014 21:22
Recurse away!

Haskell Tree

factorial :: Integral a => a -> a
factorial n
  | n < 2 = 1
  | otherwise = n * factorial (n - 1)

data Tree a =
    Empty
@queertypes
queertypes / simple.agda
Created September 29, 2014 21:06
Some fun with Agda and dependent types.
-- Agda has a notion of hierarchical Sets. This corresponds to a type
-- universe where types that live in Set0 are "smaller" than those
-- that live in Set1 define a type Bool. `Set` is Set0.
-- Here, we define a boolean type that lives in Set.
data Bool : Set where
true : Bool
false : Bool
-- functions in Agda must be total. If we omit either of these
@queertypes
queertypes / hw1-1.md
Last active August 29, 2015 14:07
Coursera Programming Languages HW 1.1 Worked Out in SML, Ocaml, Haskell, Scala

This gist demonstrates solutions to HW 1.1 in multiple languages. Avoid reading if you'd like to solve it on your own. :)

The problem

Write a function is_older that takes two dates and evaluates to true or false. It evaluates to true if
the first argument is a date that comes before the second argument. (If the two dates are the same,
the result is false.)
@queertypes
queertypes / sample.sml
Last active August 29, 2015 14:07
Standard ML in a Gist
(* This is a comment. You'll see a few of these. *)
(* This is a value binding. *)
val x = 1;
(* Names can be rebound/shadowed. This is not assignment. *)
val x = 2;
(* This is a value-binding with a type annotation. *)
val y : int = 1;
irb(main):015:0> def fact(n)
irb(main):016:1> n == 0 ? 1 : n * fact(n-1)
irb(main):017:1> end
=> :fact
irb(main):018:0> fact(10)
=> 3628800
irb(main):019:0> def facto(n)
irb(main):020:1> fact(n)
irb(main):021:1> end
=> :facto
@queertypes
queertypes / purescript-hello.md
Last active August 29, 2015 14:07
Purescript -> Javascript

Purescript

module Main where

import Debug.Trace

-- Rock, Paper, Scissors
data RPS = R | P | S