Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
以文本编码作为参数的Haskell readFile_Haskell - Fatal编程技术网

以文本编码作为参数的Haskell readFile

以文本编码作为参数的Haskell readFile,haskell,Haskell,我需要一个版本的readFile以文本编码为参数。我最终得出以下结论: readFile' e name = openFile name ReadMode >>= (flip hSetEncoding $ e) >&&> hGetContents f >&&> g = \x -> f x >> g x 有更好的方法吗 似乎我定义为&&&>的东西应该是标准的东西,但我找不到它 谢谢, Adam是liftM2(

我需要一个版本的
readFile
以文本编码为参数。我最终得出以下结论:

readFile' e name = openFile name ReadMode >>= (flip hSetEncoding $ e) >&&> hGetContents

f >&&> g = \x -> f x >> g x
  • 有更好的方法吗
  • 似乎我定义为
    &&&>
    的东西应该是标准的东西,但我找不到它
  • 谢谢,
    Adam

    liftM2(>>)
    ,导入了
    Control.Monad.Instances
    。标准库中没有更简洁的版本了。

    我认为简单的“do block”方法很适合这种情况,而不是说它更简洁


    readFile'e name=do{h或
    liftA2(>>)
    。我更喜欢
    (>)r
    的应用程序实例。我不知道为什么。:-PAlso有用:
    writeFile'e f txt=with file f WriteMode(\hdl->hSetEncoding hdl e>>hPutStr hdl txt)