我正在寻找定义,seq
并遇到了这种奇怪.为什么所有这些函数都有相同/相似的定义?
seq :: a -> b -> b
seq = let x = x in x
inline :: a -> a
inline = let x = x in x
lazy :: a -> a
lazy = let x = x in x
Run Code Online (Sandbox Code Playgroud)
源代码中有更多此定义.这是怎么回事?
我需要扫描文档并为文件中的每个字符串累积不同函数的输出.在文件的任何给定行上运行的函数取决于该行中的内容.
我可以通过为我想要收集的每个列表完整传递文件来非常低效地执行此操作.示例伪代码:
at :: B.ByteString -> Maybe Atom
at line
| line == ATOM record = do stuff to return Just Atom
| otherwise = Nothing
ot :: B.ByteString -> Maybe Sheet
ot line
| line == SHEET record = do other stuff to return Just Sheet
| otherwise = Nothing
Run Code Online (Sandbox Code Playgroud)
然后,我会将这些函数映射到文件中的整个行列表中,以获得Atoms和Sheets的完整列表:
mapper :: [B.ByteString] -> IO ()
mapper lines = do
let atoms = mapMaybe at lines
let sheets = mapMaybe to lines
-- Do stuff with my atoms …
Run Code Online (Sandbox Code Playgroud)