• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
SacalaZa #1
 

SacalaZa #1

on

  • 2,024 views

 

Statistics

Views

Total Views
2,024
Views on SlideShare
1,558
Embed Views
466

Actions

Likes
2
Downloads
4
Comments
0

3 Embeds 466

http://d.hatena.ne.jp 460
https://twitter.com 5
http://webcache.googleusercontent.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

SacalaZa #1 SacalaZa #1 Presentation Transcript

  • 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