Skip to content

Instantly share code, notes, and snippets.

@MarcelineVQ
Last active September 18, 2020 01:25
Show Gist options
  • Save MarcelineVQ/e3695adaa386f378803d577ec0d0b2d2 to your computer and use it in GitHub Desktop.
Save MarcelineVQ/e3695adaa386f378803d577ec0d0b2d2 to your computer and use it in GitHub Desktop.
`( [| ( x , y ) |] )
IAlternative
(UniqueDefault
(IApp
(IApp
(IVar (UN "<*>"))
(IApp
(IApp
(IVar (UN "<*>"))
(IApp
(IVar (UN "pure"))
(IVar (NS (MkNS ["Builtin"]) (UN "MkPair")))))
(IVar (UN "x"))))
(IVar (UN "y"))))
[IApp
(IApp
(IVar (UN "<*>"))
(IApp
(IApp
(IVar (UN "<*>"))
(IApp
(IVar (UN "pure"))
(IVar (NS (MkNS ["Builtin"]) (UN "Pair")))))
(IVar (UN "x"))))
(IVar (UN "y"))
,IApp
(IApp
(IVar (UN "<*>"))
(IApp
(IApp
(IVar (UN "<*>"))
(IApp
(IVar (UN "pure"))
(IVar (NS (MkNS ["Builtin"]) (UN "MkPair")))))
(IVar (UN "x"))))
(IVar (UN "y"))]
@MarcelineVQ
Copy link
Author

MarcelineVQ commented Sep 17, 2020

export
record Core t where
  constructor MkCore
  runCore : IO (Either String t)

pure : a -> Core a
pure x = MkCore (pure (pure x))

export
(<*>) : Core (a -> b) -> Core a -> Core b
(<*>) (MkCore f) (MkCore a) = MkCore [| f `Prelude.(<*>)` a |]

addm : Maybe Int -> Maybe Int -> Maybe Int
addm x y = [| x + y |]

pairingGood : Applicative f => f (Maybe a, Maybe b)
pairingGood = [| MkPair [| Nothing |]  [| Nothing |] |]

pairingAmbig : Applicative f => f (Maybe a, Maybe b)
pairingAmbig = [| ( [| Nothing |] , [| Nothing |] ) |]

@MarcelineVQ
Copy link
Author

pairing : Applicative f => f a -> f b -> f (a,b)
pairing x y = %runElab check  (IApp fc
                                (IApp fc 
                                  (IVar fc (UN "<*>"))
                                  (IApp fc
                                    (IApp fc
                                      (IVar fc (UN "<*>"))
                                      (IApp fc
                                        (IVar fc (UN "pure"))
                                        (IAlternative fc (UniqueDefault (IVar fc (NS (MkNS ["Builtin"]) (UN "MkPair"))))
                                           [(IVar fc (NS (MkNS ["Builtin"]) (UN "MkPair"))), (IVar fc (NS (MkNS ["Builtin"]) (UN "Pair")))])))
                                    (IVar fc (UN "x"))))
                                (IVar fc (UN "y")))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment