View Iterate.groovy
// Haskell-style iterate function in Groovy
Closure iterate(def value, Closure nextValue) {
return { value = nextValue value }
}
// use for iteration
def iter = iterate(0) { it + 1}
View RNG.java
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
import java.util.stream.Stream;
public class RNG {
static Supplier<Integer> countGen(AtomicInteger i) {
return (()-> i.getAndIncrement());
}
View SillyClock.fr
module SillyClock where
import STM
import Control.Concurrent
type Counter = TVar Int
newCounter :: STM Counter
newCounter = TVar.new 0
View ParallelStreamTest.java
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
public class ParallelStreamTest {
static class IntGenerator implements Supplier<Integer> {
private int current = 0;
View FunctionRecord.fr
module FunctionRecord where
data FRecord = FRecord {
parent :: FRecord,
name :: String,
toString :: (FRecord -> String)
}
prototype = FRecord { parent = prototype, name = undefined, toString = (\r -> r.name) }
dierk = prototype.{ name = "Dierk" }
View lab6-frege-template.fr
------------------------------------------------------------------------------------------------------------------------------
-- ROSE TREES, FUNCTORS, MONOIDS, FOLDABLES, Frege version by Dierk Koenig
------------------------------------------------------------------------------------------------------------------------------
module Lab6 where
import frege.prelude.Math(round, sin)
data Rose a = Rose a [Rose a]
derive Show Rose a
View CountdownTemplate.fr
module Countdown where
-- Countdown example from chapter 11 of Programming in Haskell,
-- Graham Hutton, Cambridge University Press, 2007.
-- Template for homework 10 in the FP101x course
-- Frege adaptions by Dierk Koenig
-- How Java's Date looks like through the Frege glasses
data Date = native java.util.Date where
View lab4-frege-template.fr
module Lab4 where
------------------------------------------------------------------------------------------------------------------------------
-- RECURSIVE FUNCTIONS, Frege version by Dierk Koenig
------------------------------------------------------------------------------------------------------------------------------
-- import frege.prelude.Math(pi) -- uncomment this when trying to use pi
-- ===================================
-- Ex. 0
View ParsingTemplate.fr
-- Functional parsing library from chapter 8 of Programming in Haskell,
-- Graham Hutton, Cambridge University Press, 2007.
-- Template file for the homework in the FP101x EdX course.
-- Read also: http://www.cs.nott.ac.uk/~gmh/monparsing.pdf
-- adapted to Frege by Dierk Koenig
-- uncomment code as needed
module Parsing where
import Data.Char
View gist:358a2bf24cdcd10044e8
import java.util.function.Function // requires Java 8
class NullSafe<T> {
protected final T t
protected NullSafe(T t) {this.t = t}
static NullSafe<T> enter(T t) { new NullSafe<T>(t) } // enter or "return" is like a constructor
// in the general case, applicative would have the type Function<T, NullSafe<T>> but we don't need that here
NullSafe<T> rightShift (Function<T,T> applicative) {