@@ -733,6 +733,45 @@ addStatics n tm ptm =
734-- Dealing with implicit arguments
734-- Dealing with implicit arguments
736+-- Add constraint bindings from using block
738+addUsingConstraints :: SyntaxInfo -> FC -> PTerm -> Idris PTerm
739+addUsingConstraints syn fc t
741+ let ns = namesIn [] ist t
742+ let cs = getConstraints t -- check declared constraints
743+ let addconsts = uconsts \\ cs
744+ -- if all names in the arguments of addconsts appear in ns,
745+ -- add the constraint implicitly
746+ return (doAdd addconsts ns t)
747+ where uconsts = filter uconst (using syn)
748+ uconst (UConstraint _ _) = True
752+ -- if all of args in ns, then add it
753+ doAdd (UConstraint c args : cs) ns t
754+ | all (\n -> elem n ns) args
755+ = PPi (Constraint False Dynamic "") (MN 0 "cu")
756+ (mkConst c args) (doAdd cs ns t)
757+ | otherwise = doAdd cs ns t
759+ mkConst c args = PApp fc (PRef fc c)
760+ (map (\n -> PExp 0 False (PRef fc n) "") args)
762+ getConstraints (PPi (Constraint _ _ _) _ c sc)
763+ = getcapp c ++ getConstraints sc
764+ getConstraints (PPi _ _ c sc) = getConstraints sc
765+ getConstraints _ = []
767+ getcapp (PApp _ (PRef _ c) args)
768+ = do ns <- mapM getName args
769+ return (UConstraint c ns)
772+ getName (PExp _ _ (PRef _ n) _) = return n
736-- Add implicit Pi bindings for any names in the term which appear in an
775-- Add implicit Pi bindings for any names in the term which appear in an
737-- argument position.
776-- argument position.
@@ -762,9 +801,13 @@ implicitise syn ignore ist tm
762 then (tm, reverse declimps)
801 then (tm, reverse declimps)
763 else implicitise syn ignore ist (pibind uvars ns tm)
802 else implicitise syn ignore ist (pibind uvars ns tm)
765− uvars = using syn
804+ uvars = map ipair (filter uimplicit (using syn))
766 pvars = syn_params syn
805 pvars = syn_params syn
807+ ipair (UImplicit x y) = (x, y)
808+ uimplicit (UImplicit _ _) = True
768 dropAll (x:xs) ys | x `elem` ys = dropAll xs ys
811 dropAll (x:xs) ys | x `elem` ys = dropAll xs ys
769 | otherwise = x : dropAll xs ys
812 | otherwise = x : dropAll xs ys
770 dropAll [] ys = []
813 dropAll [] ys = []