Skip to content

dancewithheart/agda2scala

Repository files navigation

CI

agda2scala

WIP Agda to Scala 2 and Scala 3 backend

Basic usage:

cabal run -- agda2scala ./examples/adts.agda

compile following Agda code:

module examples.adts where

-- sum types
data Rgb : Set where
  Red : Rgb
  Green : Rgb
  Blue : Rgb
{-# COMPILE AGDA2SCALA Rgb #-}

data Color : Set where
  Light : Rgb -> Color
  Dark : Rgb -> Color
{-# COMPILE AGDA2SCALA Color #-}

-- product types

record RgbPair : Set where
  constructor mkRgbPair
  field
    fst : Rgb
    snd : Bool
{-# COMPILE AGDA2SCALA RgbPair #-}

-- simple functions: const, id

const : (rgbPairArg : RgbPair) -> (rgbArg : Rgb) -> RgbPair
const rgbPairArg rgbArg = rgbPairArg
{-# COMPILE AGDA2SCALA const #-}

-- literals String

hello : String
hello = "Hello World!"
{-# COMPILE AGDA2SCALA hello #-}

into Scala code:

package examples

object adts:
  enum Rgb:
    case Red
    case Green
    case Blue

  enum Color:
    case Light(x0: Rgb)
    case Dark(x0: Rgb)

  final case class RgbPair(fst: Rgb, snd: Bool)

  def const(rgbPairArg: RgbPair, rgbArg: Rgb): RgbPair = rgbPairArg

  def hello(): String = "Hello World!"

More Agda examples

Working with source code

  • continuous compilation loop using entr
find -name '*.hs' | entr cabal test all

or using ghcid

ghcid
  • Build
cabal build all
  • Run tests
cabal test all
cabal test agda2scala-test
cabal test agda2scala-hedgehog
  • Simple way to run Scala backend
cabal run -- agda2scala --help
cabal run -- agda2scala ./examples/adts.agda
  • Generate Scala2 output
cabal run -- agda2scala --compile --no-main --out-dir=scala2/src/main/scala ./examples/adts.agda
  • Generate Scala3 (dotty) output
cabal run -- agda2scala --compile --no-main --scala-dialect=Scala3 --out-dir=scala3/src/main/scala ./examples/adts.agda
cabal run -- agda2scala --help
cabal run -- agda2scala ./examples/adts.agda
cabal run -- agda2scala --compile --no-main --out-dir=scala2/src/main/scala ./examples/adts.agda

end-to-end tests

There are Scala 3 and Scala 2 projects for code generated from Agda examples

They have unit tests, that use code generated from examples.

                agda2scala                
                (generate)                     sbt test
Agda examples ==============> src/main/scala <============ src/test/scala

checks:
* compile Agda examples
* run Scala unit tests that calls Scala code

Those tests are run on CI - Github Actions

Generate Scala 2 code from Agda examples and running tests:

cabal run -- agda2scala --compile --no-main --out-dir=scala2/src/main/scala ./examples/adts.agda
cd ../scala2
sbt ~test

generate Scala 3 code:

cabal run -- agda2scala --compile --no-main --scala-dialect=Scala3 --out-dir=scala3/src/main/scala ./examples/adts.agda
cd ../scala3
sbt ~test

Resources

About

Scala 2 and Scala 3 backend for Agda

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors