-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
125 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
module Foreign.HaskellTypes where | ||
|
||
open import Level using (Level) | ||
open import Data.Nat.Base using (ℕ) | ||
open import Data.List.Base using (List) | ||
|
||
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 | ||
|
||
instance | ||
-- Could make a macro for these kind of congruence instances. | ||
|
||
iHasHsTypeℕ : HasHsType ℕ | ||
iHasHsTypeℕ .HasHsType.HsType = ℕ | ||
|
||
iHasHsTypeList : ⦃ HasHsType A ⦄ → HasHsType (List A) | ||
iHasHsTypeList {A = A} .HasHsType.HsType = List (HsType A) | ||
|
||
iHasHsTypeFun : ⦃ HasHsType A ⦄ → ⦃ HasHsType B ⦄ → HasHsType (A → B) | ||
iHasHsTypeFun {A = A} {B = B} .HasHsType.HsType = HsType A → HsType B |
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,50 @@ | ||
{-# OPTIONS -v tc.unquote.def:10 -v tc.unquote.decl:10 -v tactic.hs-types:10 #-} | ||
|
||
module Foreign.Marshall where | ||
|
||
open import Level using (Level; 0ℓ) | ||
open import Data.Nat.Base using (ℕ) | ||
open import Data.Unit using (⊤) | ||
open import Data.List using (List; []; _∷_) | ||
open import Function.Base | ||
|
||
open import Reflection hiding (_>>=_; _>>_) | ||
open import Reflection.Syntax | ||
|
||
open import Class.Monad | ||
|
||
open import Foreign.Convertible | ||
open import Foreign.HaskellTypes | ||
import Foreign.Convertible.Deriving | ||
import Foreign.HaskellTypes.Deriving | ||
|
||
open Foreign.Convertible.Deriving | ||
open Foreign.HaskellTypes.Deriving | ||
open Foreign.Convertible.Deriving public using (autoConvertible; ConvertibleType) | ||
open Foreign.HaskellTypes.Deriving public using (autoHsType; autoHsType') | ||
|
||
private | ||
`Set = agda-sort (Sort.set (quote 0ℓ ∙)) | ||
doAutoMarshalling : Name → Term → TC ⊤ | ||
doAutoMarshalling d hole = do | ||
hsTyMeta ← newMeta `Set | ||
checkType hole (quote Convertible ∙⟦ d ∙ ∣ hsTyMeta ⟧) | ||
hsTy ← solveHsType (d ∙) | ||
unify hsTyMeta hsTy | ||
patlam ← doPatternLambda hole | ||
unify hole patlam | ||
|
||
macro | ||
autoMarshall : Name → Term → TC ⊤ | ||
autoMarshall = doAutoMarshalling | ||
|
||
data Dummy : Set where | ||
baseCase : Dummy | ||
stepCase : ℕ → Dummy | ||
|
||
instance | ||
iConvertible-ℕ = Convertible-Refl | ||
|
||
instance | ||
iHsType-Dummy = autoHsType Dummy | ||
iMarshalling-Dummy = autoMarshall Dummy |
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