:: ROGraph a = ROGraph a [ROGraph a]
:: RODGraph a = RODGraph a [RODGraph a] [RODGraph a]
buildROGraph :: (a b (c,[b])) -> Map b (ROGraph c) | Lookup MapOnList b & UpdateDefault MapOnList b & Pairs a
buildROGraph m = buildGraph m \ id val fws bws = ROGraph val fws
buildRODGraph m = buildGraph m \ id val fws bws = RODGraph val fws bws
buildGraph rawGraph constructor = futureIndex
where
raw = pairs rawGraph
forwards = buildFastMap $ flip map raw \ (id,(a,fws)) = (id,fws)
backwards = buildBackwards forwards
futureIndex = buildFastMap $ flip map raw \ (id,(a,fws)) = (id,build id a fws)
fromFuture ids = map (fromJustXXX o lookup futureIndex) ids
build nodeId contents forwards
# backwards = case lookup backwards nodeId of Just x -> x ; _ -> []
= constructor nodeId contents (fromFuture forwards) (fromFuture backwards)
buildBackwards :: (a b [c]) -> a c [b] | Empty (a c [b]) & Pairs a & UpdateDefault a c
buildBackwards graph = seqMap processNode (pairs graph) empty
where
processNode (id,forwards) = seqMapLFA forwards \ fr m = snd $ updateDefault fr (cons id) [] m
testGraph :: Map Int (Int,[Int])
testGraph = fromPairs [ @1 [2,3,4], @2 [4,1], @3 [1,2], @4 [3,4] ]
where
@ a b = (a,(a,b))
Start = printRODGraph $ fromJust $ lookup (buildRODGraph testGraph) 1
<pre> search3 :: !Bool !(u:a -> .(v:([u:a] -> w:[.b]) -> x:[.b])) u:a -> y:[.b], [v <= u,x v <= w,x v <= y] search3 kind explorer root | kind = do_all_depth [root] [] = do_all_breadth [root] [] where do_all_depth [] t = t do_all_depth [v:vs] t = explorer v \ vs` = do_all_depth vs` (do_all_depth vs t) do_all_breadth [] t = t do_all_breadth [v:vs] t = explorer v \ vs` = do_all_breadth vs (do_all_breadth vs` t) </pre>
<pre> :: Queue a = Queue !Int !.[a] !Int !.[.[a]] /* enqLen enqList deqLen deqList */ adjust :: !u:(Queue .a) -> v:(Queue .a), [u <= v] adjust q=:(Queue enqLen enqList deqLen deqList) | enqLen > 3 && enqLen >= deqLen = Queue 0 [] (enqLen + deqLen) (deqList ++ [reverse enqList]) | otherwise = q enq :: .a !u:(Queue .a) -> v:(Queue .a), [u <= v] enq a (Queue enqLen enqList deqLen deqList) = adjust (Queue (enqLen + 1) [a:enqList] deqLen deqList) deq :: !u:(Queue .a) -> (.a, !v:(Queue .a)), [u <= v] deq (Queue enqLen enqList deqLen [[]:deqList]) = deq (Queue enqLen enqList deqLen deqList) deq (Queue enqLen enqList deqLen [[a:as]:deqList]) = (a, adjust (Queue enqLen enqList (deqLen - 1) [as:deqList])) deq (Queue enqLen enqList 0 deqList) = deq (Queue 0 [] enqLen [reverse enqList]) newq :: .(Queue .a) newq = Queue 0 [] 0 [] emptyq :: !.(Queue .a) -> .Bool emptyq (Queue 0 _ 0 _) = True emptyq _ = False </pre>
1. Notion of representation 2. Notion of encoding 3. Requirements to glyphs: equality, recognisability, one might always realise where one ends and another begins 4. Deductive apparatus, mathematical theories 5. Interpretations of mathematical theories, constants 6. Variables, historic excursion into prop calc, difference between variables and constants; quantors; variable substitution and its pitfalls 7. Soundness, completeness, consistency 8. Proof theory 9. Model theory 10. What is Existence 11. What is Truth 12. Art of proof (12 lessons, first two or three are short and may be conducted together)
/* Stop >>= \a -> >>= \b insane! */
instance + (m a) | + a & Monad m
where
(+) ma mb = ma >>= \a -> mb >>= \b -> return $! a + b
instance - (m a) | - a & Monad m
where
(-) ma mb = ma >>= \a -> mb >>= \b -> return $! a - b
instance * (m a) | * a & Monad m
where
(*) ma mb = ma >>= \a -> mb >>= \b -> return $! a * b
instance / (m a) | / a & Monad m
where
(/) ma mb = ma >>= \a -> mb >>= \b -> return $! a / b
instance mod (m a) | mod a & Monad m
where
(mod) ma mb = ma >>= \a -> mb >>= \b -> return $! a mod b
instance rem (m a) | rem a & Monad m
where
(rem) ma mb = ma >>= \a -> mb >>= \b -> return $! a rem b
/* http://hpaste.org/10673 */
Fascinating excursion in monads history
The notion of monad comes from category theory. It first arose in the area of homological algebra, but later was recognised (due to the work of Kleisli and of Eilenberg and Moore) to have much wider applications.
Its importance emerged slowly: in early days, it was not even given a proper name, but called simply a "standard construction" or a "triple". The formulation used here is due to Kleisli.
Eugenio Moggi proposed that monads provide a useful
structuring tool for denotational semantics. He showed how lambda
calculus could be given call-by-value and call-by-name semantics in an
arbitrary monad, and how monads could encapsulate
a wide variety of programming language features such as state, exception handling, and continuations.
Independent of Moggi, but at about the same time, Michael Spivey proposed that monads provide a useful structuring tool for exception handling in pure functional languages, and demonstrated this thesis with an elegant program for term rewriting. He showed how monads could treat exceptions and non-deterministic choice in a common framework, thus capturing precisely a notion that I had groped towards years earlier.
Inspired byMoggi and Spivey, I proposed monads as a general technique for structuring functional programs. My early proposals were based on a special syntax for monads, that generalised list comprehensions. This was unfortunate, in that it led many to think a special syntax was needed.
This new presentation is designed to convey that monads can be profitably applied to structure programs today with existing languages.
A key observation of Moggi's was that values and computations should be assigned different types: the value type a is distinct from the computation type M a. In a call-by-value language, functions take values into computations (as in a -> M b); in a call-by-name language, functions take computations into computations (as in M a -> M b).
John Reynolds made exactly the same point a decade ago. The essence of Algol, according to Reynolds, is a programming language that distinguishes data types from phrase types. In his work data types (such as int) play the roles of values, and phrase types (such as int exp) play the role of computations, and the same distinction between call-by-value and call-by-name appears. These ideas form the basis for the design of Forsythe. But the vital unitM and bindM operations do not appear in Reynolds' work.
This is not the only time that John Reynolds has been a decade ahead of the rest of us. Among other things, he was an early promoter of continuation-passing style and the first to apply category theory to language design. One intriguing aspect of his recent work is the use of intersection types, so perhaps we should expect an upsurge of interest in that topic early in the next millenium.
-- "The essence of functional programming", Philip Wadler, University of Glasgow.
test
on Fascinating excursion in monads history