--- /dev/null
+module test
+
+:: DList a = Nil | Cons a (Link (DList a))
+:: Link a = {prev :: a, next :: a}
+
+fromList :: ([a] -> DList a)
+fromList = go Nil
+where
+ go :: (DList a) [a] -> DList a
+ go prev [] = Nil
+ go prev [a:as] =
+ let head = Cons a {prev=prev,next=tail}
+ tail = go head as
+ in head
+
+toList :: (DList a) -> [a]
+toList Nil = []
+toList (Cons el {next}) = [el:toList next]
+
+nil :: DList a
+nil = Nil
+
+(:!) infixr 0 :: a (DList a) -> DList a
+(:!) elh Nil = Cons elh {prev=nil,next=nil}
+(:!) elh (Cons elt link) =
+ let tail = Cons elt {link & prev=head}
+ head = Cons elh {prev=nil,next=tail}
+ in head
+
+Start =
+ (toList (1 :! 2 :! 3 :! nil)
+ ,toList (fromList [1,2,3])
+ )
import Text.GenPrint
import iTasks => qualified >>=, >>|, forever, sequence, return
-derive class iTask RTree, ChoiceNode
+derive class iTask RTree, ChoiceNode, FileInfo, Tm
Start w = startEngine (selectFile "/opt/clean/lib/StdLib" () False) w
toChoiceNode :: (Int a -> ChoiceNode) -> ((RTree (Int, a)) -> ChoiceNode)
toChoiceNode tfun = foldTree \a cs->{ChoiceNode | uncurry tfun a & children=cs}
- fp2cn :: Int (FilePath, Bool) -> ChoiceNode
- fp2cn i (fp, bool) = {id =if bool (~i) i,label=dropDirectory fp,icon=Nothing,expanded=False,children=[]}
+ fp2cn :: Int (FilePath, FileInfo) -> ChoiceNode
+ fp2cn i (fp, fi) = {id =if fi.directory (~i) i,label=dropDirectory fp,icon=Nothing,expanded=False,children=[]}
- fromTree :: (RTree (Int, (FilePath, Bool))) [Int] -> [FilePath]
+ fromTree :: (RTree (Int, (FilePath, a))) [Int] -> [FilePath]
fromTree tree sel = [f\\(i, (f, _))<-leafs tree | isMember i sel]
-recurseDirectory :: !FilePath !FilePath !*World -> *(MaybeOSError (RTree (FilePath, Bool)), !*World)
+recurseDirectory :: !FilePath !FilePath !*World -> *(MaybeOSError (RTree (FilePath, FileInfo)), !*World)
recurseDirectory acc fp w
# fp = acc </> fp
# (mfi, w) = getFileInfo fp w
| isError mfi = (liftError mfi, w)
# (Ok fi) = mfi
- | not fi.directory = (Ok $ RNode (fp, False) [], w)
+ | not fi.directory = (Ok $ RNode (fp, fi) [], w)
# (mcs, w) = readDirectory fp w
| isError mfi = (liftError mcs, w)
# (cs, w) = appFst sequence $ mapSt (recurseDirectory fp) (filter (\c->not (elem c [".", ".."])) (fromOk mcs)) w
- = (RNode (fp, True) <$> cs, w)
+ = (RNode (fp, fi) <$> cs, w)