Commit cde838a4 authored by Vincent Zweije's avatar Vincent Zweije
Browse files

Translate extgraph function from Miranda to Clean

parent a46f1c89
...@@ -2,6 +2,7 @@ definition module graph ...@@ -2,6 +2,7 @@ definition module graph
// $Id$ // $Id$
from pfun import Pfun
from StdOverloaded import == from StdOverloaded import ==
// A rule associating a replacement with a pattern // A rule associating a replacement with a pattern
...@@ -214,4 +215,6 @@ compilegraph :: ![(var,Node sym var)] -> Graph sym var ...@@ -214,4 +215,6 @@ compilegraph :: ![(var,Node sym var)] -> Graph sym var
*/ */
extgraph :: (Graph sym var) (Graph sym pvar) [pvar] (Pfun pvar var) (Graph sym var) -> Graph sym var | == var & == pvar
instance == (Graph sym var) | == sym & == var instance == (Graph sym var) | == sym & == var
...@@ -359,22 +359,17 @@ Uses in Miranda: ...@@ -359,22 +359,17 @@ Uses in Miranda:
`Extgraph' is excluded in most import statements, `Extgraph' is excluded in most import statements,
but there doesn't seem to be any other definition of it. but there doesn't seem to be any other definition of it.
> extgraph :: graph * ** -> graph * *** -> [***] -> pfun *** ** -> graph * ** -> graph * **
> extgraph sgraph pattern pnodes matching graph
> = foldr addnode graph pnodes
> where addnode pnode
> = total id (postcomp addnode' matching) pnode, if fst (nodecontents pattern pnode)
> = id, otherwise
> addnode' snode
> = updategraph snode scont, if sdef
> = id, otherwise
>|| = error "extgraph: closed node mapped to open node", otherwise
> || Could have used id, but let's report error when there is one...
> where (sdef,scont) = nodecontents sgraph snode
*/ */
extgraph :: (Graph sym var) (Graph sym pvar) [pvar] (Pfun pvar var) (Graph sym var) -> Graph sym var | == var & == pvar
extgraph sgraph pattern pnodes matching graph
= foldr addnode graph pnodes
where addnode pnode
= if (fst (varcontents pattern pnode)) (total id (postcomp addnode` matching) pnode) id
addnode` snode
= if sdef (updategraph snode scont) id
where (sdef,scont) = varcontents sgraph snode
mapgraph :: mapgraph ::
!( (Pfun var1 (sym1,[var1])) !( (Pfun var1 (sym1,[var1]))
-> Pfun .var2 (.sym2,[.var2]) -> Pfun .var2 (.sym2,[.var2])
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment