Skip to content

Instantly share code, notes, and snippets.

View raichoo's full-sized avatar

raichoo raichoo

View GitHub Profile
@raichoo
raichoo / gist:71a7438850b9a4aa0e7f
Created November 11, 2014 19:56
Multiline strings in Haskell
module Main where
main :: IO ()
main = putStrLn "this\n\
\is \n\
\a \n\
\test"
@raichoo
raichoo / gist:b577c7ca6c678906d92d
Last active August 29, 2015 14:07
One of my favorite subtle bug sources TypeScript inherited from JavaScript. "this".
class GimmeThis {
a : number;
constructor(a : number) {
this.a = a;
}
// When I pass this method as a function, "this"
// will be bound to the "this" at the call site.
// Should have used a function literal here to
@raichoo
raichoo / gist:a0155f83b2b3fbdcb761
Created September 26, 2014 14:57
Testing a missing JavaScript primitive
module Main
%lib Node "readline"
data ReadLine = MkReadLine Ptr
readlineClose : ReadLine -> IO ()
readlineClose (MkReadLine rl) =
mkForeign (FFun "%0.close()" [FPtr] FUnit) rl
@raichoo
raichoo / gist:d0a94883040ac6b0e7bc
Created September 21, 2014 23:51
Little Haskell Dependent Types Kata
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeOperators #-}
@raichoo
raichoo / gist:2a0e19140304bcc7d41a
Created September 18, 2014 23:18
Playing with co-patterns in Agda
{-# OPTIONS --copatterns #-}
module Test where
open import Data.Nat
open import Data.Bool
open import Data.Vec hiding (map; head; tail; take)
record Functor (F : Set → Set) : Set₁ where
field
map : ∀ {A B} → (A → B) → F A → F B
@raichoo
raichoo / gist:36a4d0388ed1f43f7808
Last active August 29, 2015 14:03
Goofing around with TypeFamilies in Haskell
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
module Test where
newtype ENumber = ENumber Int
newtype EBoolean = EBoolean Bool
data EIf c t f = EIf c t f
data EAdd l r = EAdd r l
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Web.Scotty
import Data.Text.Lazy hiding (filter)
import Control.Concurrent.STM
import Control.Monad.IO.Class
import Data.List (nub)
storeTODO :: Text -> TVar [Text] -> STM [Text]
module WTypes where
import Level
data W(S : Set)(T : S → Set) : Set where
_◁_ : (s : S) → (f : T s → W S T) → W S T
data ⊤ : Set where
⟨⟩ : ⊤
module Main
data FormatTy = FormatInt FormatTy
| FormatChar Char FormatTy
| FormatEnd
total
interpTy : FormatTy -> Type
interpTy (FormatInt ty) = Int -> interpTy ty
interpTy (FormatChar x ty) = interpTy ty
%default total
cyclicAdd : Fin 4 -> Fin 4 -> Fin 4
cyclicAdd x y = head $ drop (finToNat x + finToNat y) fins
where
fins : Stream (Fin 4)
fins = 0 :: 1 :: 2 :: 3 :: fins