This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Coord = (Int, Int) | |
type Direction = Coord -> Coord | |
type Boundary = Coord -> Bool | |
north :: Direction | |
north (row, col) = (row - 1, col) | |
south :: Direction | |
south (row, col) = (row + 1, col) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Message = Mark Word8 | Load Word64 Word64 | Undo | Reset | Legal Bool | Suggest Bool | |
newButtonPressEvent :: Int -> m -> Chan m -> IO () | |
newButtonPressEvent pinNumber msg ch = -- forkIO blah blah blah | |
-- Push msg into ch whenever a press occurs on pinNumber (rising edge, basically) | |
-- Usually used partially applied :: Int -> m -> (Chan m -> IO ()) | |
newButtonHoldEvent :: Int -> (Bool -> m) -> Chan m -> IO () | |
newButtonHoldEvent pinNumber msg ch = -- forkIO, recursive loop with lastPressed | |
-- Push msg into ch whenever a hold or release occurs on pinNumber (rising edge = hold, falling edge = releaseS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Edge = Rising | Falling | |
newGpioEdgeEventHandler :: Int -> (Edge -> Maybe m) -> Chan m -> IO () | |
-- The above function is a more general case of pressing or holding a button | |
-- Holding sends messages on the Rising and Falling edges of a GPIO pin's input | |
-- Pressing only sends messages on a Rising edge | |
-- If you want to not send a message on an edge, just have your | |
-- input function return Nothing | |
-- Otherwise, return Just m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fizzCases = [(3, "Fizz"), (5, "Buzz"), (7, "Baz")] | |
fizzBuzz :: Int -> String | |
fizzBuzz n = case (foldl fizzBuzzify "" fizzCases) of | |
"" -> show n | |
s -> s | |
where | |
fizzBuzzify acc (i, s) = if ((n `mod` i) == 0) then acc ++ s else acc | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect | |
#example state: | |
#-------------------X-------XX------XO--------------------------- O | |
if { $argc != 2 } { | |
puts "USAGE: ./go.exp <BOARD> <PLAYER>" | |
exit 1 | |
} | |
log_user 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "p24F08KL302.h" | |
//_CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2) | |
//_CONFIG2( FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_XT & FNOSC_PRI) | |
_FGS(GSS0_OFF & GWRP_OFF) | |
_FICD(ICS_PGx2) | |
_FWDT(FWDTEN_OFF) | |
_FOSC(FCKSM_CSDCMD & OSCIOFNC_ON & POSCMD_XT) | |
_FOSCSEL(FNOSC_PRI & SOSCSRC_DIG) | |
// generic helpers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FizzBuzzC | |
%default total | |
-- Dependently typed FizzBuzz, constructively | |
-- A number is fizzy if it is evenly divisible by 3 | |
data Fizzy : Nat -> Type where | |
ZeroFizzy : Fizzy 0 | |
Fizz : Fizzy n -> Fizzy (3 + n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module HList | |
% default total | |
data HList : List Type -> Type where | |
HNil : HList [] | |
(::) : t -> HList ts -> HList (t :: ts) | |
hcons : t -> HList ts -> HList (t :: ts) | |
hcons = (::) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- map is my original implementation | |
map : (f ~~> g) -> HList ts -> {auto prf : Mapper (f ~~> g) ts ts'} -> HList ts' | |
map f xs {prf} = map' f xs prf | |
-- It works for mapping head' over an HList of Lists: | |
:let xs: HList[List Int, List Bool]; xs = [[2], [True]] | |
*hlist> :let xs: HList[List Int, List Bool]; xs = [[2], [True]] | |
*hlist> :let ys2: HList[Maybe Int, Maybe Bool]; ys2=map (MkPoly(\a => head'{a=a})) xs | |
*hlist> ys2 | |
[Just 2, Just True] : HList [Maybe Int, Maybe Bool] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
/* | |
* TODO | |
* - Maybe write some macros to facilitate writing the thunks | |
* - Lazy-cons macro? (can't have lazy-cons as a function due to CbV) | |
* - Make sure my memory management strategy isn't shit | |
* - I already know that if you use malloced ptrs in the Generic | |
* it'll fuck shit up |
OlderNewer