Skip to content

Instantly share code, notes, and snippets.

View sadache's full-sized avatar

Sadek Drobi sadache

View GitHub Profile
@sadache
sadache / default-currying-lifting-idea-in.scala
Created November 20, 2009 05:17
default-currying-lifting-idea-in.scala The idea deserves maybe writing a whole paper about. But this illustrates the basic concept.
object Test {
implicit def lift0[A,B >: Any](a:A):B=>A=_=>a
implicit def lift1[A>: Any,B>: Any,C >: Any](f:A=>B):(C=>A)=>C=>A=>B = h=>c =>f (h(c))
implicit def lift2[A<:Any,B<:Any,C<:Any,D >: scala.Nothing <:scala.Any](f:Function2[A,B,C]):Function3[Function1[D,A],Function1[D,B],D,C] =( h ,g, d)=>f (h(d),g(d))
implicit def curry2[a1 >: scala.Nothing <: scala.Any, a2 >: scala.Nothing <: scala.Any, b >: scala.Nothing <: scala.Any] (f:Function2[a1,a2,b]): scala.Function1[a1, scala.Function1[a2, b]] =Function.curried(f)
implicit def curry3[a1 >: scala.Nothing <: scala.Any, a2 >: scala.Nothing <: scala.Any, a3 >: scala.Nothing <: scala.Any, b >: scala.Nothing <: scala.Any] (f:Function3[a1,a2,a3,b]): scala.Function1[a1, scala.Function1[a2,scala.Function1[a3,b]]] =Function.curried(f)
//implicit def self[A](a:A):A=a
def main(args:Array[String]){
class Program
{
static IDictionary<string,int> zipCodes= new Dictionary<string,int>{
{"Paris",75}
};
static IDictionary<int, int> population = new Dictionary<int, int>{
{75,100}
};
static int? GetInterstingNumber(string cityName){
object Application {
def main(args :Array[String]){
println(Simulator(5,5).execute((Orientations.N,(1,2)),List('G','A','G','A','G','A','G','A','A')))
println(Simulator(5,5).execute((Orientations.E,(3,3)),List('A','A','D','A','A','D','A','D','D','A')))
}
object Orientations {
type Orientation=Char
module Space.Rovers
open System
type Direction= N | E | S | W
let direction= function 'N' ->N |'E'->E |'S'->S |'W'->W
|_-> raise (new ArgumentOutOfRangeException())
let swap (x,y)=(y,x)
let rec neighbours = function N -> (W,E)
namespace TTest
{
using CircularList;
using WithCompus = Char;
//using RobotState = Tuple<IEnumerable<char>, Position>;
class Program
{
static void Main(string[] args)
{
WithCompus meWithCompusToNorth = 'N';
module Main (
) where
import Control.Monad.Either
f :: (Monad m) ⇒ Int → m Int
f 0 = fail "I don't like zeros"
f x = return x
Sandwiches:
* Jay's Cheesesteaks (many seitan flavors)
* Ike's Place (tons of amazing veggie sandwiches)
* Toaster Oven (Potbelly's clone)
Mexican:
* Papalote (their house salsa is the best IN THE WORLD)
* El Buen Sabor (my favorite super veggie burrito)
* Taqueria Cancún (classic mission burrito; open till 2am on fri/sat, 1am other days, I think)
module UrlPatterns
open System.Text.RegularExpressions
let t2 a b=(a,b)
let matchUrl pattern:string->(Map<string,string>* string ) Option=
let regex=(new Regex(pattern))
let names= regex. GetGroupNames()
in fun url -> let m=regex.Match(url)
if not(m.Success) then None
else let groups= m.Groups in
let paramMap=[for i in 0..groups.Count do
module Randexp
#r "..//Dependencies//FSharp.PowerPack.dll"
open System
open LazyList
type Lang = LazyList<String>
let (.|.) (h:Lazy<_>) (t:Lazy<_>)= LazyList.delayed <| fun()-> LazyList.consDelayed (h.Value) <| fun () -> t.Value
let rec alt (xs:Lang) (ys:Lang) :Lang=
match (xs,ys) with
LazyList.Cons(x,xt) ,LazyList.Cons(y,yt) -> match compare (String.length x, x) (String.length y, y) with
-1 -> lazy(x) .|. lazy(alt xt ys)
-----------------------------------------------------------------------------
--
-- Module : RegexLang
-- Copyright :
-- License : AllRightsReserved
--
-- Maintainer :
-- Stability :
-- Portability :
--