@@ -733,6 +733,45 @@ addStatics n tm ptm =
733733
734734-- Dealing with implicit arguments
735735
736+-- Add constraint bindings from using block
737+
738+addUsingConstraints :: SyntaxInfo -> FC -> PTerm -> Idris PTerm
739+addUsingConstraints syn fc t
740+ = do ist <- get
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
749+ uconst _ = False
750+
751+ doAdd [] _ t = t
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
758+
759+ mkConst c args = PApp fc (PRef fc c)
760+ (map (\n -> PExp 0 False (PRef fc n) "") args)
761+
762+ getConstraints (PPi (Constraint _ _ _) _ c sc)
763+ = getcapp c ++ getConstraints sc
764+ getConstraints (PPi _ _ c sc) = getConstraints sc
765+ getConstraints _ = []
766+
767+ getcapp (PApp _ (PRef _ c) args)
768+ = do ns <- mapM getName args
769+ return (UConstraint c ns)
770+ getcapp _ = []
771+
772+ getName (PExp _ _ (PRef _ n) _) = return n
773+ getName _ = []
774+
736775-- Add implicit Pi bindings for any names in the term which appear in an
737776-- argument position.
738777
@@ -762,9 +801,13 @@ implicitise syn ignore ist tm
762801 then (tm, reverse declimps)
763802 else implicitise syn ignore ist (pibind uvars ns tm)
764803 where
765− uvars = using syn
804+ uvars = map ipair (filter uimplicit (using syn))
766805 pvars = syn_params syn
767806
807+ ipair (UImplicit x y) = (x, y)
808+ uimplicit (UImplicit _ _) = True
809+ uimplicit _ = False
810+
768811 dropAll (x:xs) ys | x `elem` ys = dropAll xs ys
769812 | otherwise = x : dropAll xs ys
770813 dropAll [] ys = []