haskell

How do I use the output of a program from an earlier part of a Stack/Cabal build as source in a later part of the same build?

五迷三道 提交于 2020-05-14 16:44:25
问题 I have a very peculiar dependency situation that I would like to package up in a single Stack/Cabal package: I need to build and run my program to get the input to a code-generator which produces output that needs to be linked in to... my program. OK so in more concrete terms, here are the steps manually: stack build to install all dependencies, and build all non-Verilator-using executables. stack exec phase1 to run the first phase which generates, among other things, a Verilog file and a

How do I use the output of a program from an earlier part of a Stack/Cabal build as source in a later part of the same build?

橙三吉。 提交于 2020-05-14 16:43:05
问题 I have a very peculiar dependency situation that I would like to package up in a single Stack/Cabal package: I need to build and run my program to get the input to a code-generator which produces output that needs to be linked in to... my program. OK so in more concrete terms, here are the steps manually: stack build to install all dependencies, and build all non-Verilator-using executables. stack exec phase1 to run the first phase which generates, among other things, a Verilog file and a

How to implement lazy iterate when IO is involved in Haskell

懵懂的女人 提交于 2020-05-13 21:17:13
问题 I'm using IO to encapsulate randomness. I am trying to write a method which iterates a next function n times, but the next function produces a result wrapped in IO because of the randomness. Basically, my next function has this signature: next :: IO Frame -> IO Frame and I want to start with an initial Frame , then use the same pattern as iterate to get a list [Frame] with length n . Essentially, I'd like to be able to write the following: runSimulation :: {- parameters -} -> IO [Frame]

How to implement lazy iterate when IO is involved in Haskell

十年热恋 提交于 2020-05-13 21:17:09
问题 I'm using IO to encapsulate randomness. I am trying to write a method which iterates a next function n times, but the next function produces a result wrapped in IO because of the randomness. Basically, my next function has this signature: next :: IO Frame -> IO Frame and I want to start with an initial Frame , then use the same pattern as iterate to get a list [Frame] with length n . Essentially, I'd like to be able to write the following: runSimulation :: {- parameters -} -> IO [Frame]

How to implement lazy iterate when IO is involved in Haskell

和自甴很熟 提交于 2020-05-13 21:16:12
问题 I'm using IO to encapsulate randomness. I am trying to write a method which iterates a next function n times, but the next function produces a result wrapped in IO because of the randomness. Basically, my next function has this signature: next :: IO Frame -> IO Frame and I want to start with an initial Frame , then use the same pattern as iterate to get a list [Frame] with length n . Essentially, I'd like to be able to write the following: runSimulation :: {- parameters -} -> IO [Frame]

Most occurred within a list

泄露秘密 提交于 2020-05-13 14:17:54
问题 I have a high order function which would take: results ["Red", "Blue", "Green", "Blue", "Blue", "Red"] And return: [(1,"Green"),(2,"Red"),(3,"Blue")] I need to use the results function and create a new function called winner: winner :: [Party ] -> Party winner xs = which would output the most occurred colour and remove first element within tuples, if two colours have the same occurrences it output two the colours, for example: winner ["Red", "Blue", "Green", "Blue", "Blue", "Red"] output:

Most occurred within a list

我只是一个虾纸丫 提交于 2020-05-13 14:16:19
问题 I have a high order function which would take: results ["Red", "Blue", "Green", "Blue", "Blue", "Red"] And return: [(1,"Green"),(2,"Red"),(3,"Blue")] I need to use the results function and create a new function called winner: winner :: [Party ] -> Party winner xs = which would output the most occurred colour and remove first element within tuples, if two colours have the same occurrences it output two the colours, for example: winner ["Red", "Blue", "Green", "Blue", "Blue", "Red"] output:

What Time Complexity Does Haskell's “tail”-Function Have?

六月ゝ 毕业季﹏ 提交于 2020-05-13 07:14:05
问题 I was reading a tutorial on Haskell when I thought to myself; what time complexity does Haskell's tail function have (and why)? (I cannot find an answer in any documentation) I would guess that for a list of size n, the tail function would be O(n) , i.e just copying over the tail to a new list and returning that one. But then again, I do not know too much about the underlying architecture of Haskell (I'm new to the language). Of course, I could time it. But I don't know how to time stuff in

Could not find module ‘Control.Monad.State’ even though mtl is installed

时光总嘲笑我的痴心妄想 提交于 2020-05-13 06:19:12
问题 When I tried loading a module containing import Control.Monad.State I got Could not find module ‘Control.Monad.State’ Perhaps you meant Control.Monad.ST (from base-4.8.2.0) Control.Monad.ST.Safe (from base-4.8.2.0) Control.Monad.Fix (from base-4.8.2.0) Use -v to see a list of the files searched for. Failed, modules loaded: none. I installed the Haskell Platform, which has cabal and mtl installed. When I run cabal update and then cabal install mtl : Resolving dependencies... All the requested

Is implementing this words function possible without a postprocessing step after folding?

末鹿安然 提交于 2020-05-12 11:19:10
问题 Real World Haskell, chapter 4, page 98 of the print asks if words can be implemented using folds, and this is my question too: Is it possible? If not, why? If it is, how? I came up with the following, which is based on the idea that each non-space should be prepended to the last word in the output list (this happens in the otherwise guard), and that a space should trigger the appending of an emtpy word to the output list if there is not one already (this is handled in the if - then - else ).