Skip to content

Instantly share code, notes, and snippets.

View raichoo's full-sized avatar

raichoo raichoo

View GitHub Profile
@raichoo
raichoo / gist:2345414
Created April 9, 2012 18:50
Monads vs. implicit values in Scala
case class Config(host: String, port: Int) {
def prettyPrint(prefix: String, msg: String): String =
List(prefix, ": ", msg, " on ", host, ":", port.toString).mkString
}
/**
* Passing a configuration with implicits is like
* working in the state monad. You can "put" a
* new configuration even though we don't want that
* to happen in this particular example. We don't
@raichoo
raichoo / gist:5709002
Last active November 4, 2022 21:21
Experiments with dependently typed JSON in Idris
module JSON
import Data.SortedMap
data JSONType: Type where
JSONArray : Vect JSONType n -> JSONType
JSONString : JSONType
JSONNumber : JSONType
JSONBool : JSONType
JSONObject : SortedMap String JSONType -> JSONType
@raichoo
raichoo / notes.hs
Created September 11, 2021 12:19
Quick and dirty scale learning script
module Main where
import Control.Monad
import Data.List
import System.Random
import Data.Map (Map)
import Data.Bool
import Text.Read
import Data.Maybe
import qualified Data.Map as Map
import Control.Applicative
import Control.Monad.Fix
data CounterRep = CounterRep { x :: Int }
data Counter = Counter { get :: Int,
set :: Int -> Counter,
inc :: Counter }
counterClass = \rep ->
@raichoo
raichoo / coyo.idr
Last active October 26, 2017 22:27
Using Coyoneda to improve performance in Idris
module Main
{-
Strictness always bothers me a little, since it forces you to do
things like fusion manually. This prohibits code reuse. I won't
elaborate on this too much since there is already a great blog
post about this:
http://augustss.blogspot.co.uk/2011/05/more-points-for-lazy-evaluation-in.html
@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 / Wat.hs
Created September 7, 2017 15:44
Data.Text rewrite rules fun.
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Prelude hiding (length, filter)
import Data.Text
-- Turn on optimizations (-O) to make this `False`
wat :: Text -> Bool
wat x = length (filter (== ',') x) == 1
@raichoo
raichoo / Test.hs
Created September 5, 2017 14:17
Playing with capabilities.
module Main where
import Control.Monad
import Control.Concurrent
import Text.Printf
import Foreign.C.Types
foreign import ccall safe "getchar" c_getchar :: IO CChar
@raichoo
raichoo / gist:01969563d1a534cf4f26
Last active July 19, 2017 17:06
Typed Interpreter in Haskell
{-# OPTIONS_GHC -Wall -fno-warn-incomplete-patterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE NPlusKPatterns #-}
module Main where
function f (x)
print("f: " .. x)
return g (x + 1)
end
function g (x)
print("g: " .. x)
return f (x + 1)
end