This document discusses the benefits of functional programming (FP) that the author learned. It begins by explaining how multithreading programs are difficult to write, test, and ensure thread safety due to mutable shared state. FP avoids these issues by not using mutable variables. The document then covers some key aspects of FP like recursion, higher-order functions, function composition, and immutable data structures. It provides examples in various languages to illustrate these concepts. The author argues that FP provides a good foundation for writing concurrent programs due to its avoidance of mutable state.
ブログでもいろいろ解説しています。
http://little-hands.hatenablog.com/entry/top
ドメイン駆動設計屈指の難解な概念「境界付けられたコンテキスト」について解説します。
---
公式DDD Referenceの定義は以下の通りです。(和訳はだいぶ意訳しています)
bounded context
A description of a boundary (typically a subsystem, or the work of a particular team) within which a particular model is defined and applicable.
境界付けられたコンテキスト
特定のモデルを定義・適用する境界を明示的に示したもの。
代表的な境界の例は、サブシステムやチームなど。
まぁなかなかよくわからないですよね。DDD用語の中でもかなり難解なワードです。 境界付けられたコンテキストは、2つの観点から解説が必要でしょう。
・概念としての境界付けられたコンテキスト
・境界付けられたコンテキストをどう実装に落としこむか
今回のスライドでは、概念の方の説明をしたいと思います。
ブログでもいろいろ解説しています。
http://little-hands.hatenablog.com/entry/top
ドメイン駆動設計屈指の難解な概念「境界付けられたコンテキスト」について解説します。
---
公式DDD Referenceの定義は以下の通りです。(和訳はだいぶ意訳しています)
bounded context
A description of a boundary (typically a subsystem, or the work of a particular team) within which a particular model is defined and applicable.
境界付けられたコンテキスト
特定のモデルを定義・適用する境界を明示的に示したもの。
代表的な境界の例は、サブシステムやチームなど。
まぁなかなかよくわからないですよね。DDD用語の中でもかなり難解なワードです。 境界付けられたコンテキストは、2つの観点から解説が必要でしょう。
・概念としての境界付けられたコンテキスト
・境界付けられたコンテキストをどう実装に落としこむか
今回のスライドでは、概念の方の説明をしたいと思います。
Stardog is a fast, scalable, lightweight RDF database for complex SPARQL queries. It features OWL 2 reasoning, transactions, a robust security layer, integrity constraint validation via Pellet 3, and world-class support.
Cassandra Day 2014: Interactive Analytics with Cassandra and SparkEvan Chan
Take your analytics to the next level by using Apache Spark to accelerate complex interactive analytics using your Apache Cassandra data. Includes an introduction to Spark as well as how to read Cassandra tables in Spark.
Automation has come a long way in the last 15 years. This presentation tells the story of my journey from no automation, to running in excess of 1000 tests a day. It shares my insights, failures, successes and lessons learned, so hopefully you can get there too.
My slides form the session at sitHH at 12th May 2012 about static ABAP code analysis tools and my experience with them. Apart the tools I share my personal lessons learned for establishing a code profiling process.
Any piece of software can only be as good as its foundations. To rise as high as we need it to, we decided eZ Publish needed new ones. Today, we will tell you how these are architectured, and give you a glimpse of their possibilities.
This presentation is for enterprises that are considering adopting Scala. The author is managing editor of http://scalacourses.com, which offers self-paced online courses that teach Introductory and Intermediate Scala and Play Framework.
21. (Wikipedia)
In computer science, functional
programming is a programming paradigm
that treats computation as the evaluation
of mathematical functions and avoids state
and mutable data. It emphasizes the
application of functions, in contrast to the
imperative programming style, which
emphasizes changes in state.
Sunday, April 15, 12
22. (Wikipedia)
In computer science, functional
programming is a programming paradigm
that treats computation as the evaluation
of mathematical functions and avoids state
and mutable data. It emphasizes the
application of functions, in contrast to the
imperative programming style, which
emphasizes changes in state.
Sunday, April 15, 12
24. 目前有哪些主流
Functional Language?
Sunday, April 15, 12
25. Erlang
• Ericsson Functional Language
• No mutable variable and side effects
• For distributed, reliable, soft real-time
highly concurrent systems.
• Use the Actor model of concurrency
Sunday, April 15, 12
36. 在FP語言中,變數指
派之後就是 immutable
** Erlang R15B **
X = 1234.
X = 5678.
** exception error: no match of
right hand side value 5678
Sunday, April 15, 12
37. 在 Scala 中,使用 val
宣告變數
val a = 1234
a = 5678
<console>:8: error: reassignment to val
var b = 1234
b = 5678
5678
Sunday, April 15, 12
38. Persistent data
structure
• Immutable 的 Map, Hash, Set 等等
• 跟資料庫無關,而是因為其內部實作特性
• Produce new values by sharing structure
with existing values
Sunday, April 15, 12
39. Why need Immutable
data structure?
• No side-effects 的效能衝擊!!
• Copying overhead
Sunday, April 15, 12
40. Linked List
相加兩個List,會共享已有的資料
Sunday, April 15, 12
41. Tree (內部實作)
建立新的Tree時,共享資料
Sunday, April 15, 12
67. Haskell
add x y = x + y
add 2 3
# 5
addTwo = add 2
addTwo 3
# 5
Sunday, April 15, 12
68. Scala
用⼀一個 _ wildcard
def add(x:Int, y:Int) = x + y
val addTwo = add(2, _:Int)
addTwo(3)
//5
Sunday, April 15, 12
69. Currying
named after Haskell Curry
• 將⼀一個有 N 個參數的 function 轉換成
N 個只有⼀一個參數的 function 的過程
Sunday, April 15, 12
70. Haskell
每個 function 都是 Curried,其實都只有⼀一個參數
max 4 5
# 其實是
(max 4) 5
# max函式的宣告是
max :: Ord a => a -> (a -> a)
max 4 :: (Ord a, Num a) => a -> a
Sunday, April 15, 12
71. Haskell
每個 function 都是 Curried,其實都只有⼀一個參數
max 4 5
(max 4) 先得到⼀一個
# 其實是 Partial Function,然後再
帶入5
(max 4) 5
# max函式的宣告是
max :: Ord a => a -> (a -> a)
max 4 :: (Ord a, Num a) => a -> a
Sunday, April 15, 12
72. Scala
可以將函式定義成 Curried 形式
def sum(a: Int, b: Int) = a + b
sum(2, 3) // 5
def curriedSum(a: Int)(b: Int) = a * b
curriedSum(2)(3) // 5
curriedSum(2)
先得到⼀一個 Partial
Function,然後再帶入3
Sunday, April 15, 12
73. Compose
把兩個⼀一個參數的 Function 合併起來
可以串聯多個組合成新的函數
f(g(x)) = (f。g)(x)
Sunday, April 15, 12
74. Haskell
中間的串列省掉了
reverse( sort [2,5,1,10,5] )
# -- the '.' operator is used to
compose functions
reverseSort = reverse . sort
reverseSort [2,5,1,10,5]
Sunday, April 15, 12
75. JavaScript
也可以自定 compose 方法
function compose(f, g) {
return function(x) {
return f(g(x));
}
}
Sunday, April 15, 12
76. 5. Lazy evaluation
• 直到真的需要才執行
• 增加效率,減少沒有用到的計算
• 可以簡潔地表達無窮 list
Sunday, April 15, 12
77. Haskell is lazy
functional language
cycle [1,2,3]
# [1,2,3, 1,2,3, 1,2,3, 1,2,3, 1,2,3, 1,2,3,
1,2,3,....
take 10 (cycle [1,2,3])
# [1,2,3,1,2,3,1,2,3,1]"
Sunday, April 15, 12
78. Scala’s lazy val
useful for lazy initialization
val a = { println("evaluating A"); "A" }
// evaluating A
// a: java.lang.String = A
lazy val b = { println("evaluating B"); "B" }
// b: java.lang.String = <lazy>
Sunday, April 15, 12
82. Erlang
用來比對然後指派變數
X.
"1: variable 'X' is unbound"
X = 2.
{X, Y} = {1, 2}.
"exception error: no match of right hand side value {1,2}"
{X, Y} = {2, 3}.
{2,3}
Y.
"此時 Y 是 3"
Sunday, April 15, 12
83. Erlang
來試試 List
[H|T] = [1,2,3,4,5].
H. "1"
T. "[2,3,4,5]"
Sunday, April 15, 12
84. Erlang (cont.)
來試試 List
[A,B,C|T] = [1,2,3,4,5].
A. "1"
B. "2"
C. "3"
T. "[4,5]"
Sunday, April 15, 12
85. Scala
用 match 比對
import scala.util.Random
val randomInt = new Random().nextInt(10)
randomInt match {
case 7 => println("lucky seven")
case otherNumber => println("get " + otherNumber)
}
Sunday, April 15, 12
86. Scala
可以比對 Type
val items = List(1, "foo", 3.5)
for (item <- items) {
item match {
case i: Int => println("got an Integer: " + i)
case s: String => println("got a String: " + s)
case f: Double => println("got a Double: " + f)
case other => println("got others: " + other)
}
}
Sunday, April 15, 12
87. Scala
可以加上 Guard 條件
val t1 = ("A", "B")
val t2 = ("C", "D")
val t3 = ("E", "F")
for( tuple <- List(t1, t2, t3) ) {
tuple match {
case (one, two) if one == "C" => println("得到開頭是C的tuple")
case (one, two) => println("blah")
}
}
// blah
// Got tuple starting with C
// blah
Sunday, April 15, 12