typeclass experiments

This commit is contained in:
2024-09-07 17:25:37 -07:00
parent 7154f874bf
commit f4cbde2c98
5 changed files with 91 additions and 8 deletions

29
newt/typeclass.newt Normal file
View File

@@ -0,0 +1,29 @@
module TypeClass
-- experiment on one option for typeclass (we don't have record yet)
-- we need a bit more than this, but
data Monad : (U -> U) -> U where
MkMonad : { M : U -> U } ->
(bind : {A B : U} -> (M A) -> (A -> M B) -> M B) ->
Monad M
data Maybe : U -> U where
Just : {A : U} -> A -> Maybe A
Nothing : {A : U} -> Maybe A
-- NEXT trying to get this to work. An equivalence is not found in pattern
-- matching
-- [instance]
MaybeMonad : Monad Maybe
-- Agda case lambda might be nice..
-- The {Maybe} isn't solved in type for the case
MaybeMonad = MkMonad {Maybe} (\ {A} ma amb =>
case ma of
Nothing => Nothing
-- It doesn't discover pat$5 is A during pattern matching
-- oh, but var 0 value is var5
Just a => amb a)