8
Agate: an Agda-to-Haskell compiler AIST / CVS Hiroyuki Ozaki (joint work with Makoto Takeyama)

Agate: an Agda -to- Haskell compiler AIST / CVS Hiroyuki Ozaki (joint work with Makoto Takeyama)

Embed Size (px)

Citation preview

Page 1: Agate: an Agda -to- Haskell compiler AIST / CVS Hiroyuki Ozaki (joint work with Makoto Takeyama)

Agate:an Agda-to-Haskell compiler

AIST / CVS

Hiroyuki Ozaki

(joint work with Makoto Takeyama)

Page 2: Agate: an Agda -to- Haskell compiler AIST / CVS Hiroyuki Ozaki (joint work with Makoto Takeyama)

What is Agda?

• Proof assistant based on Martin-Löf type theory.• Curry-Howard correspondence available for its c

ore language⇒ Proof language can be regarded as a functional prog

ramming language with dependent types.

• Full language contains extension of packages, classes (therefore, monads), hidden arguments, metavariables, etc.

Page 3: Agate: an Agda -to- Haskell compiler AIST / CVS Hiroyuki Ozaki (joint work with Makoto Takeyama)

Goal

• To provide a tool for experimentation of programming with dependent types.

• To achieve it, we need– implement the tool quickly– reasonably fast execution of the emitted code– deal with “side effects,” such as I/O.

Page 4: Agate: an Agda -to- Haskell compiler AIST / CVS Hiroyuki Ozaki (joint work with Makoto Takeyama)

Requirements

• Treat full Agda language⇒ use parser of the current Agda implementation

• Faster execution⇒ compile, rather than interpret!

• Quick implementation⇒ make the target language be Haskell

⇒Agda language is close to it and there is GHC which generates executable binaries of high quality

⇒ use Higher Order Abstract Syntax⇒to eliminate coding for variable substitution

Page 5: Agate: an Agda -to- Haskell compiler AIST / CVS Hiroyuki Ozaki (joint work with Makoto Takeyama)

Our HOAS Tree

data Val = VAbs (Val -> Val) | VCon String [Val] | VStr [(String, Val)] | VIO (IO Val) | VString Stringapply :: Val -> Val -> Valapply (VAbs f) v = f vselect :: Val -> String -> Valselect (VStr bs) x = lookup x bs

E.g.,(∖x -> x) zero ⇨ VAbs (∖x -> x) `apply` (VCon “zero” [])

struct { inc = ∖x -> succ x; n = inc zero}

⇨ let inc = VAbs (∖x -> succ `apply` x)

n = inc `apply` zero in VStr [(“n”,n),(“inc”,inc)]

Untyped lambda calculus for representing Agda terms

Page 6: Agate: an Agda -to- Haskell compiler AIST / CVS Hiroyuki Ozaki (joint work with Makoto Takeyama)

How to deal with IOPass the buck to Haskell!posutulate IO :: Set -> Setposutulate putStr :: String -> IO Unitmain :: IO Unitmain = putStr “Hello World”

data Val = … | VIO (IO Val) | VString String

deIO (VIO m) = mdeString (VString s) = s

x_main, x_putStr :: Valx_main = x_putStr `apply` VString “Hello World”x_putStr = VAbs (∖v -> VIO (putStr (deString v) >> return VUnit ))main :: IO Valmain = deIO x_main

Page 7: Agate: an Agda -to- Haskell compiler AIST / CVS Hiroyuki Ozaki (joint work with Makoto Takeyama)

Performance

GHC : Agate = 1 : 6 (execution time)

Agda

Agate (sec) GHC (sec) ratio

fact 8 0.130 0.022 5.9

fib 20 0.071 0.012 5.9

ack 3 6 0.130 0.037 3.5

Page 8: Agate: an Agda -to- Haskell compiler AIST / CVS Hiroyuki Ozaki (joint work with Makoto Takeyama)

Conclusion

• Running under Linux, Windows and MacOSX

• Visit my homepage to download Agate!http://staff.aist.go.jp/hiroyuki.ozaki/

Availability

• FULL dependently typed functional language including IO, with a very sophisticated development environment