Slicing and Functional Programming Simon Thompson University of - PowerPoint PPT Presentation
Slicing and Functional Programming Simon Thompson University of Kent Haskell and Erlang Pure language Impure language but has monads but single assignment Strongly typed Weakly typed Lazy evaluation
Slicing and Functional Programming Simon Thompson University of Kent
Haskell and Erlang • Pure language … • Impure language … • … but has monads • … but single assignment • Strongly typed • Weakly typed • Lazy evaluation • Strict evaluation • Sequential core • Concurrent
Concurrency in Erlang -module(echo). -export([go/0, loop/0]). go() -> loop() -> Pid = spawn(echo, loop, []), receive Pid ! {self(), hello}, {From, Msg} -> receive From ! {self(), Msg}, {Pid, Msg} -> loop(); io:format("~w~n",[Msg]) stop -> end, true Pid ! stop. end.
Laziness in Haskell if True t f = t • Arguments are only if False t f = f evaluated when needed. if (2>3) ⊥ 4 ↝ 4 • Arguments are only sft (a:b:xs) = a+b evaluated to the extent ones = 1:ones that is needed for sft ones ↝ 2 evaluation to proceed.
Slicing parseMessage :: MessageList -> (Message, MessageList) parseMessage [] = ([], []) parseMessage xs = (takeWhile (/= ’&’) (tail ys), dropWhile (/= ’&’) (tail ys) ) where ys = dropWhile (/= ’&’) xs parseMsgL :: MessageList -> Message parseMsgL [] = [] parseMsgL xs = takeWhile (/= ’&’) (tail (dropWhile (/= ’&’) xs))
Clone detection • Search for common generalisation. • What about insertion, deletion or permutation of statements? • Can slicing help?
Ideas • Slicing for debugging functional programs. • Slicing components of complex structures. • … and others … ?
Recommend
More recommend
Explore More Topics
Stay informed with curated content and fresh updates.