SlideShare une entreprise Scribd logo
1  sur  35
Scala

        ocaml-nagoya / mzp




                       2010-09-04 ScalaZa #1
                1
•                  / mzp

• http://twitter.com/mzp
• SE(not Scala)
•

                     2
10%
                          love
                          hate
            45%
                          neither
45%




                      (        )
                  3
10%           Yes
                    No



90%


                (         )
            4
Scala
   Java
       Integer x = inc(42)



   Scala
           val x = inc(42)



                  5
..



6
def inc(n : Int ) : Int =
  n + 1


      (          )


             7
def id[T](x : T) =
  x



        8
9
def inc(x) = x + 1



def inc(x : Int) : Int


                10
def id(x) = x



def id[T](x : T): T


              11
Scala 3.0                                  !




http://d.hatena.ne.jp/kmizushima/20100401/p1
                     12
Scala3.0




           13
Hindley-Milner

•
    •                    (   )

•
• OCaml   Haskell


                    14
←
         Types and Programming
            Laungages(TAPL)




•            2

•   15
Scalet
•   Scala + let      = Scalet

•   http://bitbucket.org/mzp/scalet/
    •      : 376 ,                    : 262

•                  Scala

    •                   implicit conversion   .
                                ...

                           16
17
•
•   int     bool

•     let     if   fn        3

•
                        18
19
AST


  AST




      20
• case
sealed abstract class Term

//
case class Var(name : String) extends Term

// λ    fn x => x + 1
case class Lambda(arg : String,body : Term) extends Term

//         f x
case class Apply(f : Term,arg : Term) extends Term
...

                             21
•
//
def varref : Parser[Term] = ident ^^ (Var((_ :
String)))

// λ
def lambda : Parser[Term] =
  (keyword("fn") ~> ident <~ keyword("->")) ~ term ^^
  {
    case x~body => Lambda(x,body)
  }

//
def term : Parser[Term] = (lambda | varref | .. )
                           22
•
def eval(term : Term) : Term =
  term match {
    //
        case Var(_) | Lambda(_,_) | ... =>
          term
        // f x
        case Apply(Lambda(x,body),y @ Value()) =>
          body.subst(x -> y).eval
        // f x f                     x
        case Apply(x @ Value(),y) =>
          Apply(x,y eval).eval
        // f x       f
        case Apply(x,y) =>
          Apply(x eval,y).eval
        ....
}
                                 23
• case
   •                         (ry
sealed abstract class Type
// Int
case class Int() extends Type
// Bool
case class Bool() extends Type
//
case class TVar(name : String) extends Type
//
case class ->:(from : Type,to : Type) extends Type

                        24
:
                              plus1 : int -> int

                                          :
                           x :α
let plus2 x =
                         → plus1 : α -> β
  plus1 (plus1 x)
                         → plus1 : β ->γ
                           plus2 : α -> γ
                                        (        ):
                              plus2 : int -> int
                    25
def constrain(term : Term, env : Map[String,Type]) :
(Type,TypeConstrain) =
  term match {
    case Var(name) =>
      //
      (env(name),TypeConstrain())
    case Lambda(arg,body) =>
      // λ
      val x = TypeInfer gensym
      val (t,c) = body.constrain(env + (arg -> x))
      (x ->: t,c)
    case Apply(f,arg) =>
      //
      val (t1,c1) = f constrain env
      val (t2,c2) = arg constrain env
      val x = TypeInfer gensym
      val c = c1 ++ c2 + (t1 -> (t2 ->: x))
      (x,c)
    ...                         26
}
(                                 )
def unify() : Map[String,Type] =
  types match {
    case List() =>
      Map()
    case x::xs =>
      val ys = new TypeConstrain(xs)
      x match {
        case (s,t) if(s == t) =>
          ys unify
          ....
      }
  }

                 27
28
Hindley-Milner
•              Hindley    Milner



•
        (Principal Type   )

•
•
                29
Scala                   (      )
  •
  • Scala 3.0   ..
            def f(x) = x.close



def f[A <: { def close(): Unit }](x :
A): Unit

                     30
(   )
•            Java

    •                                   ?

    • Java                      Scala       ?

    • Java         Scala
               ?

                           31
•
•
    •                     Scala



• Scala3.0   (   )

                     32
• Benjamin-Pierce, Types and Programming
  Laungages
• Scala by Example
 • http://www.scala-lang.org/docu/files/
    ScalaByExample.pdf



                     33
One more thing....



        34
!




•
• http://github.com/mzp/lambda/
                    35

Contenu connexe

Tendances

Introduction to idris
Introduction to idrisIntroduction to idris
Introduction to idrisConor Farrell
 
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsQuark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsJohn De Goes
 
The Object Oriented Paradigm in perspective
The Object Oriented Paradigm in perspectiveThe Object Oriented Paradigm in perspective
The Object Oriented Paradigm in perspectiveRuben Gonzalez Blanco
 
Scala Types of Types @ Lambda Days
Scala Types of Types @ Lambda DaysScala Types of Types @ Lambda Days
Scala Types of Types @ Lambda DaysKonrad Malawski
 
Railroading into Scala
Railroading into ScalaRailroading into Scala
Railroading into ScalaNehal Shah
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheoryKnoldus Inc.
 
Scala-对Java的修正和超越
Scala-对Java的修正和超越Scala-对Java的修正和超越
Scala-对Java的修正和超越Caoyuan Deng
 
16 - Scala. Type of length-indexed vectors
16 - Scala. Type of length-indexed vectors16 - Scala. Type of length-indexed vectors
16 - Scala. Type of length-indexed vectorsRoman Brovko
 
Scalaz 8: A Whole New Game
Scalaz 8: A Whole New GameScalaz 8: A Whole New Game
Scalaz 8: A Whole New GameJohn De Goes
 
42.type: Literal-based Singleton types
42.type: Literal-based Singleton types42.type: Literal-based Singleton types
42.type: Literal-based Singleton typesGeorge Leontiev
 
Seductions of Scala
Seductions of ScalaSeductions of Scala
Seductions of ScalaDean Wampler
 
Javascript arrays
Javascript arraysJavascript arrays
Javascript arraysHassan Dar
 
Practical scalaz
Practical scalazPractical scalaz
Practical scalazoxbow_lakes
 
麻省理工C++公开教学课程(二)
麻省理工C++公开教学课程(二)麻省理工C++公开教学课程(二)
麻省理工C++公开教学课程(二)ProCharm
 
Programming haskell chapter10
Programming haskell chapter10Programming haskell chapter10
Programming haskell chapter10Kousuke Ruichi
 

Tendances (19)

Introduction to idris
Introduction to idrisIntroduction to idris
Introduction to idris
 
1.2 scala basics
1.2 scala basics1.2 scala basics
1.2 scala basics
 
Scala Bootcamp 1
Scala Bootcamp 1Scala Bootcamp 1
Scala Bootcamp 1
 
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsQuark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
 
The Object Oriented Paradigm in perspective
The Object Oriented Paradigm in perspectiveThe Object Oriented Paradigm in perspective
The Object Oriented Paradigm in perspective
 
Scala Types of Types @ Lambda Days
Scala Types of Types @ Lambda DaysScala Types of Types @ Lambda Days
Scala Types of Types @ Lambda Days
 
Typeclasses
TypeclassesTypeclasses
Typeclasses
 
Railroading into Scala
Railroading into ScalaRailroading into Scala
Railroading into Scala
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheory
 
Scala-对Java的修正和超越
Scala-对Java的修正和超越Scala-对Java的修正和超越
Scala-对Java的修正和超越
 
16 - Scala. Type of length-indexed vectors
16 - Scala. Type of length-indexed vectors16 - Scala. Type of length-indexed vectors
16 - Scala. Type of length-indexed vectors
 
Scala Intro
Scala IntroScala Intro
Scala Intro
 
Scalaz 8: A Whole New Game
Scalaz 8: A Whole New GameScalaz 8: A Whole New Game
Scalaz 8: A Whole New Game
 
42.type: Literal-based Singleton types
42.type: Literal-based Singleton types42.type: Literal-based Singleton types
42.type: Literal-based Singleton types
 
Seductions of Scala
Seductions of ScalaSeductions of Scala
Seductions of Scala
 
Javascript arrays
Javascript arraysJavascript arrays
Javascript arrays
 
Practical scalaz
Practical scalazPractical scalaz
Practical scalaz
 
麻省理工C++公开教学课程(二)
麻省理工C++公开教学课程(二)麻省理工C++公开教学课程(二)
麻省理工C++公开教学课程(二)
 
Programming haskell chapter10
Programming haskell chapter10Programming haskell chapter10
Programming haskell chapter10
 

En vedette

Scala基礎勉強会: Featherweight Scalaの紹介および型付け規則の決定可能性について
Scala基礎勉強会: Featherweight Scalaの紹介および型付け規則の決定可能性についてScala基礎勉強会: Featherweight Scalaの紹介および型付け規則の決定可能性について
Scala基礎勉強会: Featherweight Scalaの紹介および型付け規則の決定可能性についてHiroki Mizuno
 
Coq for Moblie Phone @ ML名古屋
Coq for Moblie Phone @ ML名古屋Coq for Moblie Phone @ ML名古屋
Coq for Moblie Phone @ ML名古屋Hiroki Mizuno
 
#NGK2012B Excelによる設計書について
#NGK2012B Excelによる設計書について#NGK2012B Excelによる設計書について
#NGK2012B Excelによる設計書についてHiroki Mizuno
 
TypeSafe OSの試み
TypeSafe OSの試みTypeSafe OSの試み
TypeSafe OSの試みHiroki Mizuno
 
OCamlでWebアプリケーションを作るn個の方法
OCamlでWebアプリケーションを作るn個の方法OCamlでWebアプリケーションを作るn個の方法
OCamlでWebアプリケーションを作るn個の方法Hiroki Mizuno
 

En vedette (8)

どこでもCoq
どこでもCoqどこでもCoq
どこでもCoq
 
Java基礎
Java基礎Java基礎
Java基礎
 
Scala基礎勉強会: Featherweight Scalaの紹介および型付け規則の決定可能性について
Scala基礎勉強会: Featherweight Scalaの紹介および型付け規則の決定可能性についてScala基礎勉強会: Featherweight Scalaの紹介および型付け規則の決定可能性について
Scala基礎勉強会: Featherweight Scalaの紹介および型付け規則の決定可能性について
 
Coq for Moblie Phone @ ML名古屋
Coq for Moblie Phone @ ML名古屋Coq for Moblie Phone @ ML名古屋
Coq for Moblie Phone @ ML名古屋
 
Sml#探検隊
Sml#探検隊Sml#探検隊
Sml#探検隊
 
#NGK2012B Excelによる設計書について
#NGK2012B Excelによる設計書について#NGK2012B Excelによる設計書について
#NGK2012B Excelによる設計書について
 
TypeSafe OSの試み
TypeSafe OSの試みTypeSafe OSの試み
TypeSafe OSの試み
 
OCamlでWebアプリケーションを作るn個の方法
OCamlでWebアプリケーションを作るn個の方法OCamlでWebアプリケーションを作るn個の方法
OCamlでWebアプリケーションを作るn個の方法
 

Similaire à SacalaZa #1

Type Classes in Scala and Haskell
Type Classes in Scala and HaskellType Classes in Scala and Haskell
Type Classes in Scala and HaskellHermann Hueck
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data ManagementAlbert Bifet
 
Functional programming with_scala
Functional programming with_scalaFunctional programming with_scala
Functional programming with_scalaRaymond Tay
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesTomer Gabel
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?Tomasz Wrobel
 
Speaking Scala: Refactoring for Fun and Profit (Workshop)
Speaking Scala: Refactoring for Fun and Profit (Workshop)Speaking Scala: Refactoring for Fun and Profit (Workshop)
Speaking Scala: Refactoring for Fun and Profit (Workshop)Tomer Gabel
 
Scala Refactoring for Fun and Profit
Scala Refactoring for Fun and ProfitScala Refactoring for Fun and Profit
Scala Refactoring for Fun and ProfitTomer Gabel
 
Comparing Haskell & Scala
Comparing Haskell & ScalaComparing Haskell & Scala
Comparing Haskell & ScalaMartin Ockajak
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to ScalaBrian Hsu
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that LetterKevlin Henney
 
The Scala Programming Language
The Scala Programming LanguageThe Scala Programming Language
The Scala Programming Languageleague
 
Types by Adform Research
Types by Adform ResearchTypes by Adform Research
Types by Adform ResearchVasil Remeniuk
 
Advance Scala - Oleg Mürk
Advance Scala - Oleg MürkAdvance Scala - Oleg Mürk
Advance Scala - Oleg MürkPlanet OS
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with ScalaDenis
 
Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010JUG Lausanne
 

Similaire à SacalaZa #1 (20)

Type Classes in Scala and Haskell
Type Classes in Scala and HaskellType Classes in Scala and Haskell
Type Classes in Scala and Haskell
 
Introducing scala
Introducing scalaIntroducing scala
Introducing scala
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
 
Functional programming with_scala
Functional programming with_scalaFunctional programming with_scala
Functional programming with_scala
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
 
Speaking Scala: Refactoring for Fun and Profit (Workshop)
Speaking Scala: Refactoring for Fun and Profit (Workshop)Speaking Scala: Refactoring for Fun and Profit (Workshop)
Speaking Scala: Refactoring for Fun and Profit (Workshop)
 
Scala Refactoring for Fun and Profit
Scala Refactoring for Fun and ProfitScala Refactoring for Fun and Profit
Scala Refactoring for Fun and Profit
 
Comparing Haskell & Scala
Comparing Haskell & ScalaComparing Haskell & Scala
Comparing Haskell & Scala
 
A bit about Scala
A bit about ScalaA bit about Scala
A bit about Scala
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
The Scala Programming Language
The Scala Programming LanguageThe Scala Programming Language
The Scala Programming Language
 
Scala on Android
Scala on AndroidScala on Android
Scala on Android
 
Types by Adform Research
Types by Adform ResearchTypes by Adform Research
Types by Adform Research
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
Advance Scala - Oleg Mürk
Advance Scala - Oleg MürkAdvance Scala - Oleg Mürk
Advance Scala - Oleg Mürk
 
An introduction to scala
An introduction to scalaAn introduction to scala
An introduction to scala
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with Scala
 
Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010
 

Plus de Hiroki Mizuno

Darcs紹介@20120423-scmbc
Darcs紹介@20120423-scmbcDarcs紹介@20120423-scmbc
Darcs紹介@20120423-scmbcHiroki Mizuno
 
Gallinaによる証明駆動開発の魅力
Gallinaによる証明駆動開発の魅力Gallinaによる証明駆動開発の魅力
Gallinaによる証明駆動開発の魅力Hiroki Mizuno
 
CoqによるMsgPackの証明
CoqによるMsgPackの証明CoqによるMsgPackの証明
CoqによるMsgPackの証明Hiroki Mizuno
 
「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)Hiroki Mizuno
 
20110424 action scriptを使わないflash勉強会
20110424 action scriptを使わないflash勉強会20110424 action scriptを使わないflash勉強会
20110424 action scriptを使わないflash勉強会Hiroki Mizuno
 
Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Coq to Rubyによる証明駆動開発@名古屋ruby会議02Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Coq to Rubyによる証明駆動開発@名古屋ruby会議02Hiroki Mizuno
 
証明駆動開発のたのしみ@名古屋reject会議
証明駆動開発のたのしみ@名古屋reject会議証明駆動開発のたのしみ@名古屋reject会議
証明駆動開発のたのしみ@名古屋reject会議Hiroki Mizuno
 
Coqによる証明駆動開発
Coqによる証明駆動開発Coqによる証明駆動開発
Coqによる証明駆動開発Hiroki Mizuno
 
NGK忘年会 2010 / CoqからRubyへ
NGK忘年会 2010 / CoqからRubyへNGK忘年会 2010 / CoqからRubyへ
NGK忘年会 2010 / CoqからRubyへHiroki Mizuno
 
From Coq to Ruby / CoqからRubyへ
From Coq to Ruby / CoqからRubyへFrom Coq to Ruby / CoqからRubyへ
From Coq to Ruby / CoqからRubyへHiroki Mizuno
 
OCamlAPISearchの紹介
OCamlAPISearchの紹介OCamlAPISearchの紹介
OCamlAPISearchの紹介Hiroki Mizuno
 
Proove Mark&Sweep GC with Coq
Proove Mark&Sweep GC with CoqProove Mark&Sweep GC with Coq
Proove Mark&Sweep GC with CoqHiroki Mizuno
 
CoqでGCの証明をしてみたよ(LT)
CoqでGCの証明をしてみたよ(LT)CoqでGCの証明をしてみたよ(LT)
CoqでGCの証明をしてみたよ(LT)Hiroki Mizuno
 

Plus de Hiroki Mizuno (14)

Darcs紹介@20120423-scmbc
Darcs紹介@20120423-scmbcDarcs紹介@20120423-scmbc
Darcs紹介@20120423-scmbc
 
Gallinaによる証明駆動開発の魅力
Gallinaによる証明駆動開発の魅力Gallinaによる証明駆動開発の魅力
Gallinaによる証明駆動開発の魅力
 
CoqによるMsgPackの証明
CoqによるMsgPackの証明CoqによるMsgPackの証明
CoqによるMsgPackの証明
 
「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)
 
20110424 action scriptを使わないflash勉強会
20110424 action scriptを使わないflash勉強会20110424 action scriptを使わないflash勉強会
20110424 action scriptを使わないflash勉強会
 
Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Coq to Rubyによる証明駆動開発@名古屋ruby会議02Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Coq to Rubyによる証明駆動開発@名古屋ruby会議02
 
証明駆動開発のたのしみ@名古屋reject会議
証明駆動開発のたのしみ@名古屋reject会議証明駆動開発のたのしみ@名古屋reject会議
証明駆動開発のたのしみ@名古屋reject会議
 
Coqによる証明駆動開発
Coqによる証明駆動開発Coqによる証明駆動開発
Coqによる証明駆動開発
 
NGK忘年会 2010 / CoqからRubyへ
NGK忘年会 2010 / CoqからRubyへNGK忘年会 2010 / CoqからRubyへ
NGK忘年会 2010 / CoqからRubyへ
 
From Coq to Ruby / CoqからRubyへ
From Coq to Ruby / CoqからRubyへFrom Coq to Ruby / CoqからRubyへ
From Coq to Ruby / CoqからRubyへ
 
CoqUn2010
CoqUn2010CoqUn2010
CoqUn2010
 
OCamlAPISearchの紹介
OCamlAPISearchの紹介OCamlAPISearchの紹介
OCamlAPISearchの紹介
 
Proove Mark&Sweep GC with Coq
Proove Mark&Sweep GC with CoqProove Mark&Sweep GC with Coq
Proove Mark&Sweep GC with Coq
 
CoqでGCの証明をしてみたよ(LT)
CoqでGCの証明をしてみたよ(LT)CoqでGCの証明をしてみたよ(LT)
CoqでGCの証明をしてみたよ(LT)
 

SacalaZa #1

  • 1. Scala ocaml-nagoya / mzp 2010-09-04 ScalaZa #1 1
  • 2. / mzp • http://twitter.com/mzp • SE(not Scala) • 2
  • 3. 10% love hate 45% neither 45% ( ) 3
  • 4. 10% Yes No 90% ( ) 4
  • 5. Scala Java Integer x = inc(42) Scala val x = inc(42) 5
  • 7. def inc(n : Int ) : Int = n + 1 ( ) 7
  • 8. def id[T](x : T) = x 8
  • 9. 9
  • 10. def inc(x) = x + 1 def inc(x : Int) : Int 10
  • 11. def id(x) = x def id[T](x : T): T 11
  • 12. Scala 3.0 ! http://d.hatena.ne.jp/kmizushima/20100401/p1 12
  • 13. Scala3.0 13
  • 14. Hindley-Milner • • ( ) • • OCaml Haskell 14
  • 15. Types and Programming Laungages(TAPL) • 2 • 15
  • 16. Scalet • Scala + let = Scalet • http://bitbucket.org/mzp/scalet/ • : 376 , : 262 • Scala • implicit conversion . ... 16
  • 17. 17
  • 18. • • int bool • let if fn 3 • 18
  • 19. 19
  • 20. AST AST 20
  • 21. • case sealed abstract class Term // case class Var(name : String) extends Term // λ fn x => x + 1 case class Lambda(arg : String,body : Term) extends Term // f x case class Apply(f : Term,arg : Term) extends Term ... 21
  • 22. • // def varref : Parser[Term] = ident ^^ (Var((_ : String))) // λ def lambda : Parser[Term] = (keyword("fn") ~> ident <~ keyword("->")) ~ term ^^ { case x~body => Lambda(x,body) } // def term : Parser[Term] = (lambda | varref | .. ) 22
  • 23. • def eval(term : Term) : Term = term match { // case Var(_) | Lambda(_,_) | ... => term // f x case Apply(Lambda(x,body),y @ Value()) => body.subst(x -> y).eval // f x f x case Apply(x @ Value(),y) => Apply(x,y eval).eval // f x f case Apply(x,y) => Apply(x eval,y).eval .... } 23
  • 24. • case • (ry sealed abstract class Type // Int case class Int() extends Type // Bool case class Bool() extends Type // case class TVar(name : String) extends Type // case class ->:(from : Type,to : Type) extends Type 24
  • 25. : plus1 : int -> int : x :α let plus2 x = → plus1 : α -> β plus1 (plus1 x) → plus1 : β ->γ plus2 : α -> γ ( ): plus2 : int -> int 25
  • 26. def constrain(term : Term, env : Map[String,Type]) : (Type,TypeConstrain) = term match { case Var(name) => // (env(name),TypeConstrain()) case Lambda(arg,body) => // λ val x = TypeInfer gensym val (t,c) = body.constrain(env + (arg -> x)) (x ->: t,c) case Apply(f,arg) => // val (t1,c1) = f constrain env val (t2,c2) = arg constrain env val x = TypeInfer gensym val c = c1 ++ c2 + (t1 -> (t2 ->: x)) (x,c) ... 26 }
  • 27. ( ) def unify() : Map[String,Type] = types match { case List() => Map() case x::xs => val ys = new TypeConstrain(xs) x match { case (s,t) if(s == t) => ys unify .... } } 27
  • 28. 28
  • 29. Hindley-Milner • Hindley Milner • (Principal Type ) • • 29
  • 30. Scala ( ) • • Scala 3.0 .. def f(x) = x.close def f[A <: { def close(): Unit }](x : A): Unit 30
  • 31. ( ) • Java • ? • Java Scala ? • Java Scala ? 31
  • 32. • • • Scala • Scala3.0 ( ) 32
  • 33. • Benjamin-Pierce, Types and Programming Laungages • Scala by Example • http://www.scala-lang.org/docu/files/ ScalaByExample.pdf 33

Notes de l'éditeur