This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Gtk; | |
using WebKit; | |
namespace monobrowser { | |
class coolbrowser { | |
public static void Main () { | |
Application.Init (); | |
Window window = new Window ("a browser in 13 lines..."); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Gtk; | |
public partial class MainWindow: Gtk.Window | |
{ | |
public MainWindow () : base (Gtk.WindowType.Toplevel) | |
{ | |
Window myWin = new Window ("My first GTK# Application!"); | |
myWin.Resize (200, 200); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AndroidDesignerView.cs | |
// | |
// Author: | |
// Lluis Sanchez <[email protected]> | |
// | |
// Copyright (c) 2011 Xamarin Inc | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the "Software"), to deal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Gtk; | |
namespace builder | |
{ | |
class MainWin | |
{ | |
[Gtk.Builder.Object("window1")] Window window1; | |
public void OnToggled(object sender, EventArgs args) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.kafecho.learning.monad | |
import java.util.UUID | |
/** My attempt at implementing the Reader Monad concept. | |
* The Reader Monad encapsulates a computation which: | |
* - requires a dependency of type D | |
* - produces values of type A. | |
*/ | |
case class Reader[D, A](computation: D => A) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Start by creating a reader for some fake yet conceivable type for executing SQL queries. */ | |
val dbReader: Reader[Properties, JdbcExecutor] = | |
for { | |
driver <- read[String]("db.driver") | |
uri <- read[String]("db.uri") | |
user <- read[String]("db.username") | |
password <- read[String]("db.password") | |
name <- read[String]("db.pool.name") | |
minCons <- read[Int]("db.pool.minConnections") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val getJDBCConnection: Reader[JDBCConf, Connection] = ??? | |
val getStatement: Reader[Connection, PreparedStatement] = ??? | |
val executeQuery: Reader[PreparedStatement, ResultSet] = ??? | |
val queryExecutor: Reader[JDBCConf, ResultSet] = getJDBCConnection.andThen(getStatement).andThen(executeQuery) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Monad | effect | sequences the effect as | M[A] | bind: M[A] => (f: A => M[B]) => M[B] | |
Identity | nothing | continue | Id[A] | f(a) | |
Option | zero or one value (anonymous exception) | halt if None | Option[A] | if Some(a) f(a) | |
Either | exception with error type or one value | halt if Left | Either[L, A] | if Right(a) f(a) | |
List | any # of values (non-determinism) | halt if empty | List[A] | join(each f(a)) | |
Reader | an environment; dependency-injection | function composition | R => A | (r: R) => f(a(r)) | |
Writer | logging | append log value W | Writer[W, A](log: W, value: A) | k = f(a.value); Writer(a.log |+| k.log, k.value) | |
State | state | new state from old | State[S, A](s: S => (S, A)) | | |
Responder | continuation-passing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// REPL Testing | |
// | |
// ----------------------------------------- | |
$ scala | |
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_20). | |
Type in expressions for evaluation. Or try :help. | |
scala> case class Reader[C, A](g: C => A) { | |
| def apply(c: C) = g(c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Based on the first part of the talk "Dead-Simple Dependency Injection in Scala" by @runarorama at NEScala 2012 | |
http://marakana.com/s/dependency_injection_in_scala,1108/index.html | |
*/ | |
class Connection { | |
def prepareStatement(query: String) = new Statement() | |
} | |
class Statement { |