我是Haskell的新手,读了一些博客说Haskell代码非常优雅。但是我写的Haskell代码看起来一点也不优雅。 我想要改进的几个方面是:
I use case matches on Either values a lot, is using something like fromRight from Data.Either a better option? I also have some code with nested structures, for right values
case eitherResponse of Right response -> return $ toJSON $ response Left msg -> Log $ "Error" <> msg
I have a lot of code which looks like this
fname <- URI.mkPathPiece functionname kch <- URI.mkPathPiece $ T.pack "channel" vch <- URI.mkPathPiece channel kca <- URI.mkPathPiece $ T.pack "chaincode" vca <- URI.mkPathPiece chaincode let path = Just (True, Data.List.NonEmpty.fromList [fname, kch, vch, kca, vca])
此外,对我而言,Haskell非常类似于"do"块中的命令式编程。这是Haskell代码应该看起来的样子吗?还是我走错了方向?
IO
,那么_调用它的顶层函数_也需要是IO
。但是,如果它们不需要IO
,那么它调用的所有其他函数都可以是普通的纯函数。 - leftaroundabout