@@ -322,12 +322,17 @@ getClause :: Int -- ^ line number that the type is declared on
322322 -> Name -- ^ Function name
323323 -> FilePath -- ^ Source file name
324324 -> Idris String
325−getClause l fn fp = do ty <- getInternalApp fp l
326− ist <- get
327− let ap = mkApp ist ty []
328− return (show fn ++ " " ++ ap ++
329− "= ?" ++ show fn ++ "_rhs")
330− where mkApp i (PPi (Exp _ _ False) (MN _ _) ty sc) used
325+getClause l fn fp
326+ = do i <- getIState
327+ case lookupCtxt fn (idris_classes i) of
328+ [c] -> return (mkClassBodies i (class_methods c))
329+ _ -> do ty <- getInternalApp fp l
330+ ist <- get
331+ let ap = mkApp ist ty []
332+ return (show fn ++ " " ++ ap ++ "= ?"
333+ ++ show fn ++ "_rhs")
334+ where mkApp :: IState -> PTerm -> [Name] -> String
335+ mkApp i (PPi (Exp _ _ False) (MN _ _) ty sc) used
331336 = let n = getNameFrom i used ty in
332337 show n ++ " " ++ mkApp i sc (n : used)
333338 mkApp i (PPi (Exp _ _ False) (UN n) ty sc) used
@@ -349,6 +354,19 @@ getClause l fn fp = do ty <- getInternalApp fp l
349354 ns -> uniqueNameFrom (mkSupply ns) used
350355 getNameFrom i used _ = uniqueName (sUN "x") used
351356
357+ -- write method declarations, indent with 4 spaces
358+ mkClassBodies :: IState -> [(Name, (FnOpts, PTerm))] -> String
359+ mkClassBodies i ns
360+ = showSep "\n"
361+ (zipWith (\(n, (_, ty)) m -> " " ++
362+ def (show (nsroot n)) ++ " "
363+ ++ mkApp i ty []
364+ ++ "= ?"
365+ ++ show fn ++ "_rhs_" ++ show m) ns [1..])
366+
367+ def n@(x:xs) | not (isAlphaNum x) = "(" ++ n ++ ")"
368+ def n = n
369+
352370getProofClause :: Int -- ^ line number that the type is declared
353371 -> Name -- ^ Function name
354372 -> FilePath -- ^ Source file name