-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from lemastero/id-function
Handle identity function
- Loading branch information
Showing
6 changed files
with
183 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,29 @@ | ||
module examples.adts where | ||
|
||
-- simple sum type no arguments - sealed trait + case objects | ||
-- simple product type no arguments - sealed trait + case objects | ||
|
||
data Rgb : Set where | ||
Red : Rgb | ||
Green : Rgb | ||
Blue : Rgb | ||
{-# COMPILE AGDA2SCALA Rgb #-} | ||
|
||
-- simple sum type with arguments - sealed trait + case class | ||
data Bool : Set where | ||
True : Bool | ||
False : Bool | ||
{-# COMPILE AGDA2SCALA Bool #-} | ||
|
||
-- trivial function with single argument | ||
|
||
idRgb : Rgb -> Rgb | ||
idRgb x = x | ||
{-# COMPILE AGDA2SCALA idRgb #-} | ||
|
||
-- simple sum type - case class | ||
|
||
data Color : Set where | ||
Light : Rgb -> Color | ||
Dark : Rgb -> Color | ||
{-# COMPILE AGDA2SCALA Color #-} | ||
record RgbPair : Set where | ||
constructor mkRgbPair | ||
field | ||
fst : Rgb | ||
snd : Bool | ||
{-# COMPILE AGDA2SCALA RgbPair #-} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
package adts | ||
object adts { | ||
|
||
sealed trait Rgb | ||
case object Red extends Rgb | ||
case object Green extends Rgb | ||
case object Blue extends Rgb | ||
|
||
sealed trait Color | ||
case object Light extends Color | ||
case object Dark extends Color | ||
sealed trait Bool | ||
case object True extends Bool | ||
case object False extends Bool | ||
|
||
def idRgb(x: Rgb): Rgb = x | ||
|
||
final case class RgbPair(snd: Bool, fst: Rgb) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters