View lab6-frege-template.fr
1 2 3 4 5 6 7 8 9 10
------------------------------------------------------------------------------------------------------------------------------
-- 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
1 2 3 4 5 6 7 8 9 10
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
1 2 3 4 5 6 7 8 9 10
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
1 2 3 4 5 6 7 8 9 10
-- 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
1 2 3 4 5 6 7 8 9 10
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) {
View ExampleTests.fr
1 2 3 4 5
module realworld.experiments.ExampleTests where
 
test_that_is_expected_to_pass = 1 == 1
 
test_that_is_expected_to_fail = 1 == 2
View FregeSpec.groovy
1 2 3 4 5 6 7 8 9 10
//@Grab('org.spockframework:spock-core:0.7-groovy-2.0')
import spock.lang.*
 
import java.lang.reflect.Field
 
class FregeSpec extends Specification {
@Shared Class testClass = realworld.experiments.ExampleTests
@Shared List<Field> testFields = testClass.fields.findAll { Field it -> it.modifiers == 25 && it.name.startsWith("test") }
 
@Unroll
View GroovyDelegatingTrait
1 2 3 4 5 6 7 8 9
// has all methods of List
trait ListLike {
@Delegate List linkedList = new LinkedList()
}
 
// stores anything but exposes only Strings
class StringList implements ListLike {
String get(int index) { linkedList.get(index).toString() }
}
View ModularGroovyTraits
1 2 3 4 5 6 7 8 9 10
trait HasId {
long id
}
trait HasVersion {
long version
}
trait Persistent {
boolean save() { println "saving ${this.dump()}" }
}
trait Entity implements Persistent, HasId, HasVersion {
View CallJSR223.groovy
1 2 3 4 5 6 7 8 9
package com.canoo
 
import javax.script.*
 
//Get the Frege Script Engine
final frege = new ScriptEngineManager().getEngineByName("frege")
 
//Evaluate an expression
println frege.eval('show $ take 10 [2,4..]')
Something went wrong with that request. Please try again.