haskell

Generating documentation for my own code with Haddock and stack

别来无恙 提交于 2020-12-29 02:36:39
问题 I have annotated my code in Haddock style and would like to generate browse-able documentation. Since I am also using stack, I want to integrate the documentation generation into the workflow. However, I have not yet been able to generate anything useful. I can run stack haddock and it will generate documentation in the style I want (to be found deep inside ~/.stack/ ), but it only seems to generate documentation for the packages I depend on, rather than for my own code. When I run stack

replacement / substition with Haskell regex libraries

时光怂恿深爱的人放手 提交于 2020-12-28 06:55:07
问题 Is there a high-level API for doing search-and-replace with regexes in Haskell? In particular, I'm looking at the Text.Regex.TDFA or Text.Regex.Posix packages. I'd really like something of type: f :: Regex -> (ResultInfo -> m String) -> String -> m String so, for example, to replace "dog" with "cat" you could write runIdentity . f "dog" (return . const "cat") -- :: String -> String or do more advanced things with the monad, like counting occurrences, etc. Haskell documentation for this is

replacement / substition with Haskell regex libraries

夙愿已清 提交于 2020-12-28 06:49:12
问题 Is there a high-level API for doing search-and-replace with regexes in Haskell? In particular, I'm looking at the Text.Regex.TDFA or Text.Regex.Posix packages. I'd really like something of type: f :: Regex -> (ResultInfo -> m String) -> String -> m String so, for example, to replace "dog" with "cat" you could write runIdentity . f "dog" (return . const "cat") -- :: String -> String or do more advanced things with the monad, like counting occurrences, etc. Haskell documentation for this is

Can not load a file that uses standard libraries in haskell

隐身守侯 提交于 2020-12-26 08:10:11
问题 Hi I use GHCI and can normally load my files. Now I need to load a file that uses random. I get this error. Chatterbot.hs:3:1: error: Could not find module ‘System.Random’ Use -v to see a list of the files searched for. | 3 | import System.Random | ^^^^^^^^^^^^^^^^^^^^ This is very weird since it works for my friend who also have just installed GHCI and did nothing other than me. The main difference is that I am on windows. I really don t understand this and have tried googling a bit and many

Is it possible to create a Monad that count the number of instructions?

妖精的绣舞 提交于 2020-12-26 05:55:47
问题 Thinking about monad, it came to me the idea of a monad as the way to break with the Von Neumann architecture. The Von Neumann architecture uses a set of instructions (called program) to change the data in memory and the execution of each instruction of the program updates a program counter to know whom instruction is the next to execute. If we think about the Von Neumann architecture as a monad, the bind operator (>>=) update the program counter. We can make a Monad that break Von Neumann

How to view higher-order functions and IO-actions from a mathematical perspective?

左心房为你撑大大i 提交于 2020-12-26 04:03:51
问题 I am trying to understand functional programming from first principles, yet I am stuck on the interface between the pure functional world and the impure real world that has state and side effects. From a mathematical perspective, what is a function that returns a function? what is a function that returns an IO action (like Haskell's IO type)? To elaborate: In my understanding, a pure function is a map from domain to co-domain. Ultimately, it is a map from some values in computer memory to

How to view higher-order functions and IO-actions from a mathematical perspective?

别等时光非礼了梦想. 提交于 2020-12-26 04:00:09
问题 I am trying to understand functional programming from first principles, yet I am stuck on the interface between the pure functional world and the impure real world that has state and side effects. From a mathematical perspective, what is a function that returns a function? what is a function that returns an IO action (like Haskell's IO type)? To elaborate: In my understanding, a pure function is a map from domain to co-domain. Ultimately, it is a map from some values in computer memory to

What is the best way to split a string by a delimiter functionally?

假装没事ソ 提交于 2020-12-24 08:12:49
问题 I tried to write the program in Haskell that will take a string of integer numbers delimitated by comma, convert it to list of integer numbers and increment each number by 1. For example "1,2,-5,-23,15" -> [2,3,-4,-22,16] Below is the resulting program import Data.List main :: IO () main = do n <- return 1 putStrLn . show . map (+1) . map toInt . splitByDelimiter delimiter $ getList n getList :: Int -> String getList n = foldr (++) [] . intersperse [delimiter] $ replicate n inputStr delimiter

What is the best way to split a string by a delimiter functionally?

…衆ロ難τιáo~ 提交于 2020-12-24 08:11:34
问题 I tried to write the program in Haskell that will take a string of integer numbers delimitated by comma, convert it to list of integer numbers and increment each number by 1. For example "1,2,-5,-23,15" -> [2,3,-4,-22,16] Below is the resulting program import Data.List main :: IO () main = do n <- return 1 putStrLn . show . map (+1) . map toInt . splitByDelimiter delimiter $ getList n getList :: Int -> String getList n = foldr (++) [] . intersperse [delimiter] $ replicate n inputStr delimiter

What is the best way to split a string by a delimiter functionally?

倾然丶 夕夏残阳落幕 提交于 2020-12-24 08:10:22
问题 I tried to write the program in Haskell that will take a string of integer numbers delimitated by comma, convert it to list of integer numbers and increment each number by 1. For example "1,2,-5,-23,15" -> [2,3,-4,-22,16] Below is the resulting program import Data.List main :: IO () main = do n <- return 1 putStrLn . show . map (+1) . map toInt . splitByDelimiter delimiter $ getList n getList :: Int -> String getList n = foldr (++) [] . intersperse [delimiter] $ replicate n inputStr delimiter