-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use reflection to generate Haskell types (#488)
* first draft of generating Haskell version of types * start on tying everything together * macro to generate all the marshalling for a type in one go * generate HsTypes for records * wip: generate haskell types * Turn off verbosity for inlining tactic * Clean up and fixes of Haskell type generation * Start on generating Ledger types * Auto generating all the ledger types * Better control over names of generated Haskell code * Use GHC Rationals * Hack for RoseTree-like recursive types * More field prefixes * Fix import in Lib.hs * Tests pass! * Macro to generate type aliases for HsTypes * Fix minor things * Remove `Ledger.Foreign.LedgerTypes` * Cleanup * Fix Haskell compilation --------- Co-authored-by: whatisRT <[email protected]>
- Loading branch information
Showing
28 changed files
with
1,176 additions
and
1,687 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
module Foreign.HaskellTypes where | ||
|
||
open import Level using (Level) | ||
open import Data.Bool.Base using (Bool) | ||
open import Data.Nat.Base using (ℕ) | ||
open import Data.String.Base using (String) | ||
open import Data.List.Base using (List) | ||
open import Data.Maybe.Base using (Maybe) | ||
open import Data.Sum.Base using (_⊎_) | ||
open import Data.Product.Base using (_×_) | ||
open import Data.Unit using (⊤) | ||
|
||
open import Foreign.Haskell.Pair using (Pair) | ||
open import Foreign.Haskell.Either using (Either) | ||
|
||
private variable | ||
l : Level | ||
A B : Set l | ||
|
||
record HasHsType (A : Set l) : Set₁ where | ||
field | ||
HsType : Set | ||
|
||
HsType : (A : Set l) → ⦃ HasHsType A ⦄ → Set | ||
HsType _ ⦃ i ⦄ = i .HasHsType.HsType | ||
|
||
MkHsType : (A : Set l) (Hs : Set) → HasHsType A | ||
MkHsType A Hs .HasHsType.HsType = Hs | ||
|
||
instance | ||
|
||
iHsTy-ℕ = MkHsType ℕ ℕ | ||
iHsTy-Bool = MkHsType Bool Bool | ||
iHsTy-⊤ = MkHsType ⊤ ⊤ | ||
iHsTy-String = MkHsType String String | ||
|
||
-- Could make a macro for these kind of congruence instances. | ||
iHsTy-List : ⦃ HasHsType A ⦄ → HasHsType (List A) | ||
iHsTy-List {A = A} .HasHsType.HsType = List (HsType A) | ||
|
||
iHsTy-Maybe : ⦃ HasHsType A ⦄ → HasHsType (Maybe A) | ||
iHsTy-Maybe {A = A} .HasHsType.HsType = Maybe (HsType A) | ||
|
||
iHsTy-Fun : ⦃ HasHsType A ⦄ → ⦃ HasHsType B ⦄ → HasHsType (A → B) | ||
iHsTy-Fun {A = A} {B = B} .HasHsType.HsType = HsType A → HsType B | ||
|
||
iHsTy-Sum : ⦃ HasHsType A ⦄ → ⦃ HasHsType B ⦄ → HasHsType (A ⊎ B) | ||
iHsTy-Sum {A = A} {B = B} .HasHsType.HsType = Either (HsType A) (HsType B) | ||
|
||
iHsTy-Pair : ⦃ HasHsType A ⦄ → ⦃ HasHsType B ⦄ → HasHsType (A × B) | ||
iHsTy-Pair {A = A} {B = B} .HasHsType.HsType = Pair (HsType A) (HsType B) |
Oops, something went wrong.