Skip to content

Instantly share code, notes, and snippets.

View mmhelloworld's full-sized avatar

Marimuthu Madasamy mmhelloworld

View GitHub Profile
@mmhelloworld
mmhelloworld / TestFregeTutorial.js
Created November 27, 2012 23:00
Test Frege tutorial
toc={1:4157860}
@mmhelloworld
mmhelloworld / FregeTutorial.md
Created November 27, 2012 23:11
Frege Tutorial Test 1

Test Frege Tutorial

@mmhelloworld
mmhelloworld / gist:4465496
Last active December 10, 2015 17:08
Bibi the Smart Frog is playing a jumping game on an m x n rectangular board. There is a number written in each cell of the board (Bibi can read these numbers since he is very smart!) Bibi starts the game by picking any cell on the board and stays there. At each step, Bibi will jump to another cell. He can either: Jump to the right to a cell in t…
import Data.Array
import Data.List
data Direction = DRight | DDown
isValid (a, b) board = a >= 0 && a <= m && b >= 0 && b <= n where
(_, (m, n)) = bounds board
canMove board (a, b) (DRight, step) = isValid (a, b + step) board &&
board ! (a, b + step) >= board ! (a, b)
@mmhelloworld
mmhelloworld / Foo.fr
Last active December 15, 2015 15:09
Test Frege-Java interop
module fregeforjava.Foo where
class A a where
f1 :: a -> Bool
f2 :: a -> Int -> [a]
data D1 = D1 String Int
derive Show D1
@mmhelloworld
mmhelloworld / Main.java
Created March 31, 2013 06:24
Test Frege-Java interop
package javacallingfrege;
import frege.prelude.PreludeBase.TList;
import frege.prelude.PreludeText;
import fregeforjava.Foo;
public class Main {
public static void main(final String[] args) {
// Get the instance of D1 for class 'A'
final Foo.CA aInst = Foo.IA_D1.it;
@mmhelloworld
mmhelloworld / ProcessTest.fr
Created May 17, 2013 03:11
Run a process (drip launching clojure here for example) using Frege
module hellofrege.ProcessTest where
data ProcessBuilder = mutable native java.lang.ProcessBuilder where
native new :: MutableIO StringArr -> IO ProcessBuilder
native redirectErrorStream :: ProcessBuilder -> Bool -> IO ()
native start :: ProcessBuilder -> IO Process throws IOException
native directory :: ProcessBuilder -> MutableIO File -> IO ProcessBuilder
data Process = mutable native java.lang.Process where
native getOutputStream :: Process -> IO OutputStream
@mmhelloworld
mmhelloworld / InterpreterTest.scala
Last active December 18, 2015 04:39
Embed Scala REPL
object InterpreterTest {
import scala.tools.nsc._
import interpreter._
def break(params: NamedParam*): Unit = {
val repl = new ILoop
repl.settings = new Settings
repl.settings.Yreplsync.value = true
repl.in = SimpleReader()
repl.createInterpreter
@mmhelloworld
mmhelloworld / JavaList.fr
Created June 17, 2013 06:23
Java List in Frege
module hellofrege.JavaList where
data LinkedList a = native java.util.LinkedList where
native add :: Mutable s (LinkedList a) -> a -> ST s Bool
native get :: Mutable s (LinkedList a) -> Int -> ST s (Maybe a)
native new :: () -> STMutable s (LinkedList a)
fromFregeList :: [a] -> STMutable s (LinkedList a)
fromFregeList xs = LinkedList.new () >>= loop xs where
loop (x:xs) jlist = LinkedList.add jlist x >> loop xs jlist
@mmhelloworld
mmhelloworld / FregeScriptEngineTest.java
Created June 28, 2013 06:14
JSR 223 - Scripting support for Frege
package helloworld;
import javax.script.Compilable;
import javax.script.CompiledScript;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
public class FregeScriptEngineTest {
public static void main(final String[] args) throws Exception {
@mmhelloworld
mmhelloworld / QuicksortInversion.fr
Created August 16, 2013 02:20
Quicksort with local mutation in ST monad with Java collections in Frege
module helloworld.QuicksortInversion where
--Quicksort with inversion
qsort :: Ord a => [a] -> ([a], Int)
qsort xs = ST.run go where
go = do
jlist <- ArrayList.fromList xs
inv <- Ref.new 0 -- initialize the inversion as 0
let qsortImperative !from !to
| from < to = do