Skip to content

Instantly share code, notes, and snippets.

@sgraf812
Last active September 25, 2016 08:53
Show Gist options
  • Save sgraf812/65478af1f8d795590d463b6432e71c9f to your computer and use it in GitHub Desktop.
Save sgraf812/65478af1f8d795590d463b6432e71c9f to your computer and use it in GitHub Desktop.
import Reverse
import Prelude hiding (reverse)
main :: IO ()
main = print $ reverse [1, 2, 3]
module Reverse (reverse) where
import Prelude hiding (foldr, reverse)
foldr :: (a -> acc -> acc) -> acc -> [a] -> acc
foldr _ acc [] = acc
foldr f acc (x:xs) = f x (foldr f acc xs)
reverse :: [a] -> [a]
reverse xs = foldr (flip (.) . (:)) id xs []

Hypothetical co-call signatures for module Reverse (assuming that foldr isn't inlined):

binder E0  E1 E2 E3 E4 E5
foldr {} {f}2 {f, acc}2 C3 ∪ {(f,f)} E3·x4 ((E3·x4)·x5)
reverse {} C1 (still {}) E1·x2 E1·x2·x3 E1·x2·x3·x4 E1·x2·x3·x4·x5

Cn is the complete graph in n nodes without self-edges, V2 is the complete graph of all nodes in V with self-edges.

G·x (left-assoc) inserts x into the graph and adds an edge to every node in V(G)∪{x}. xi are non-formal arguments added via possible eta-expansion (are those even necessary?) in the scenario were the function call is over-saturated, e.g. the call to foldr in the body of reverse. (Not so sure about this part, do we need self-edges or not?)

If I'm not missing something, there should be no loss in precision compared to doing the analysis without signatures.

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