Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntactical plugin to improve ergonomics #30

Open
L-as opened this issue Oct 14, 2022 · 1 comment
Open

Syntactical plugin to improve ergonomics #30

L-as opened this issue Oct 14, 2022 · 1 comment

Comments

@L-as
Copy link
Member

L-as commented Oct 14, 2022

\x -> y -> maybePLam \x -> y
A x y z -> maybePCon $ A x y z
case x of { ... } -> maybePMatch x \case { ... }
Similarly for pattern guards, and other built-in syntax that can't be overloaded.

# Class-based solution
class MaybePLam x y out | out -> x y where
  maybePLam :: (x -> y) -> out

instance PLC e => MaybePLam (Term e a) (Term e b) (Term e (a #-> b)) where
  maybePLam = plam
  
instance {-# OVERLAPPABLE #-} PLC e => MaybePLam a b (a -> b) where
  maybePLam = id
  
# Type-family-based solution
type family F1 (x :: Type) :: Type where
  F1 (Term e (a #-> b)) = Term e a
  F1 (a -> b) = a

type family F2 (x :: Type) :: Type where
  F2 (Term e (a #-> b)) = Term e b
  F2 (a -> b) = b

type family IsTermFunc (x :: Type) :: Bool where
  F2 (Term e (_ #-> _)) = 'True
  F2 (a -> b) = 'False

maybePLam :: KnownBool (IsTermFunc out) => (F1 out -> F2 out) -> out
maybePLam = ...
@L-as
Copy link
Member Author

L-as commented Apr 18, 2023

phadej/overloaded#44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant