- 188 名前:デフォルトの名無しさん mailto:sage [2005/10/25(火) 23:17:03 ]
- // haskellの真似 とか調べたことでも書いてみる
foldrWithReadline:: !(String a-> a) a !*File -> (a, *File) foldrWithReadline proc knil file #! (end,file) = fend file | end = (knil, file) #! (line, file) = freadline file # (lines , file) = foldrWithReadline proc knil file = ((proc (trimNewline line) lines), file) foldrWithReader:: !(*File->(Bool,a,*File)) !(a b->b) b !*File -> (b, *File) foldrWithReader reader proc knil file #! (ok, token, file) = reader file | not ok = (knil, file) # (tokens , file) = foldrWithReader reader proc knil file = ((proc token tokens), file) foldrWithReadChar:: !(Char a-> a) !a !*File -> (a, *File) foldrWithReadChar x y z = foldrWithReader freadc x y z readFile :: !String *World -> ([String],*World) readFile path wld = callWithInputFile path (\x -> abort ("readFile :: " +++ path )) (foldrWithReadline (\x y -> [x:y]) []) wld readFileChar :: !String *World -> ([Char],*World) readFileChar path wld = callWithInputFile path (\x -> abort ("readFileChar :: " +++ path)) (foldrWithReadChar (\x y -> [x:y]) []) wld
|

|