Skip to content

Instantly share code, notes, and snippets.

View takahisa's full-sized avatar

Takahisa Watanabe takahisa

  • Cybozu, Inc
  • Tokyo, Japan
View GitHub Profile
let _8 = fun _9 -> _9 in
let rec _0 _1 _10 =
let _11 = fun _3 -> _10 _3 in
if _1 < 0 then
_11 0
else
_0 (_1 - 1) (fun _6 -> _11 (_1 + _6))
in (_0 10) (fun _2 -> _8 _2)
hamming :: [Int]
hamming = filter p [1..]
where
p :: Int -> Bool
p x | x `mod` 5 == 0 = p (x `div` 5)
| x `mod` 3 == 0 = p (x `div` 3)
| x `mod` 2 == 0 = p (x `div` 2)
| otherwise = x == 1
main :: IO ()
@takahisa
takahisa / syb1.hs
Last active January 17, 2017 00:25
Scrap_Your_Boilerplate_1
{-# LANGUAGE DeriveDataTypeable #-}
module Main where
import Data.Generics
import Data.Data
import Data.Typeable
data Exp = Add Exp Exp | Sub Exp Exp | Val Int
deriving (Show, Eq, Typeable, Data)
eval :: Exp -> Exp
@takahisa
takahisa / syb2.ml
Created January 17, 2017 00:24
Scrap_Your_Boilerplate_2
type (_, _) eql = Refl : ('a, 'a) eql
type _ type_rep = ..
module type TYPEABLE =
sig
type t
val type_rep : unit -> t type_rep
val eqty : 's type_rep -> (t, 's) eql option
end
@takahisa
takahisa / one-liner.sh
Created January 22, 2017 14:31
Batch Indentation with Emacs
find . -name "*.ml" -exec emacs --batch {} --eval '(progn (indent-region (point-min) (point-max) nil) (save-buffer))' \;
@takahisa
takahisa / gist:755638333a0fd334819bd8c7d3f4a9a9
Created May 18, 2017 08:39
Extensible VariantsとClassによるOpen-Recursionを用いた拡張可能なインタプリタ
(*
* Extensible VariantsとClassによるOpen-Recursionを用いた拡張可能なインタプリタ
* [author] linerlock
* [update] 2017/05/18
*)
module type SYNTAX = sig
type var
type tpe = ..
type exp = ..
(*
* Copyright (c) 2017 Takahisa Watanabe <[email protected]> All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
(*
* Copyright (c) 2017 Takahisa Watanabe <[email protected]> All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@takahisa
takahisa / tagless-final-style.ml
Created July 31, 2017 02:49
Extensible Interpreter/Tagless Final Approach
module type SYM_base = sig
type 'a repr
val lam: ('a repr -> 'b repr) -> ('a -> 'b) repr
val app: ('a -> 'b) repr -> 'a repr -> 'b repr
end
module type SYM_bool = sig
include SYM_base
val bool: bool -> bool repr
val not_: bool repr -> bool repr
@takahisa
takahisa / f-bound-type-encoding.cs
Created August 2, 2017 04:11
Generics (F-bound type) approach
namespace ExpressionProblem {
using System;
interface Exp<E> where E: Exp<E> { }
class Int<E>: Exp<E> where E: Exp<E> {
public int Value { get; set; }
}
class Add<E>: Exp<E> where E: Exp<E> {
public E Operand0 { get; set; }