Skip to content

Instantly share code, notes, and snippets.

View mmhelloworld's full-sized avatar

Marimuthu Madasamy mmhelloworld

View GitHub Profile
@mmhelloworld
mmhelloworld / JdbcExample.idr
Created January 16, 2017 07:18
An Idris example using a database with JDBC and idris-jvm
module Main
import IdrisJvm.IO
namespace ResultSet
ResultSet : Type
ResultSet = JVM_Native $ Interface "java/sql/ResultSet"
next : ResultSet -> JVM_IO Bool
@mmhelloworld
mmhelloworld / ConversionBetweenHaskellAndJavaLists.hs
Last active February 29, 2016 07:28
Haskell on the JVM via GHCJS and Nashorn
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE JavaScriptFFI #-}
{-# LANGUAGE UnliftedFFITypes #-}
{-# LANGUAGE GHCForeignImportPrim #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE TypeFamilies #-}
@mmhelloworld
mmhelloworld / froogle.txt
Created January 18, 2016 17:40
Froogle text database
-- | Public interface for the various prelude modules
module frege.Prelude
-- | The Java @!@ operator on booleans
(!) :: Bool -> Bool
-- | A head strict variant of (:)
--
-- This will be used in list comprehensions
package helloworld;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import static java.lang.String.format;
import static java.lang.System.out;
import static java.util.Arrays.asList;
@mmhelloworld
mmhelloworld / HelloWorld.fr
Last active August 29, 2015 14:17
Extending Java classes, implementing interfaces all in Frege without writing Java
module mmhelloworld.hellofrege.HelloWorld where
import mmhelloworld.hellofrege.Script
import Java.Util (List)
-- Implement Runnable interface
newRunnable :: ST s () -> ST s (Mutable s Runnable)
newRunnable action = jsMethod1ST script "Runnable" "create" action where
script =
"var JRunnable = Java.type('java.lang.Runnable'); \n" ++
@mmhelloworld
mmhelloworld / AppletSupport.java
Created April 7, 2014 02:48
Java Applets with Frege
package fregeappletsupport;
import javax.swing.JApplet;
import javax.swing.SwingUtilities;
import fregeapplet.HelloApplet;
/**
* A starter class since Frege cannot extend a Java class
*
@mmhelloworld
mmhelloworld / NanoParsec.fr
Last active August 29, 2015 13:57
Test ":load" command on REPL
--- Small parser, inspired by Parsec, but much less versatile
module testfrege.data.NanoParsec where
import Data.List
import Prelude.PreludeBase (StringJ)
import Data.Monoid
import Test.QuickCheck as Q()
{--
@mmhelloworld
mmhelloworld / Regex.fr
Created December 26, 2013 06:13
Frege Regex
frege> pure native groupCount :: Matcher -> Int
frege> match s regex = groups <$> (s =~ regex) where groups m = [m.group i | i <- [1..groupCount m]]
frege> Just (Just year: Just month: Just day: _) = "2011-07-15" `match` #(\d\d\d\d)-(\d\d)-(\d\d)#
frege> println [year, month, day]
["2011", "07", "15"]
@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
@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 {