I have a list (rs) of lists of length 4 with integers from 0..7, I would like a function to return a list of length 8 that has at each index the number of times said integers appear...
This seems awfully simple but I can't do shit... All I can think of is concatenating the list but then I don't know how to even proceed. I keep thinking of just iterating over arrays and adding state...
[i | i <- concat rs ]submitted by AceCream
[link] [6 comments]
I'm trying to implement a loop that prints an integer timer value from getPOSIXTime. This is my first attempt at composing monads and I'm fresh from completing LYAH (which didn't go into transformers, I have looked at a few resources on transformers but most of the examples are too complex for me to follow or weren't specific to IO + State).
I have about 40 lines of code here that I've managed to at least get the type checker to accept, but I'm not getting any output to the console:module Timer ( runTimer ) where import Control.Monad import Control.Monad.State import Data.Time.Clock.POSIX import Data.Int type ClockTime = Int64 posixToClockTime :: POSIXTime -> ClockTime posixToClockTime x = floor $ (read $ init $ show x) * 1000 curTime :: IO ClockTime curTime = posixToClockTime `fmap` getPOSIXTime newTime :: ClockTime -> State ClockTime Bool newTime newtime = state $ \oldtime -> if (oldtime < newtime) then (True, newtime) else (False, oldtime) runTimer :: StateT ClockTime IO () runTimer = forever $ do newtime <- lift curTime oldtime <- get let (b,_) = runState (newTime newtime) oldtime if (b == True) then lift $ putStrLn $ show newtime else do return ()
Ideally runTimer would loop and print the timestamp when it has changed, otherwise doing nothing.
I can call return runTimer from a GHCi prompt, but nothing is output and it returns immediately.
Basically, is there a way to get this to run or am I barking up the wrong tree?submitted by D_duck
[link] [8 comments]
Hi, i have a list like ["5","4"] and i would like to use the function read to get the value of each elements in my list
i know that i can doread "5" :: Int
but how can i apply that for an entire list?
I was thinking about using map likemap read ["5","4"] :: Int
ormap read ["5"::Int, "4":: Int]
but it does not work as far as i can tell.
Any help would be nice, sorry for the newbie question ^submitted by superancetre
[link] [4 comments]
(This is partly a genuine question, but there's also a bit of musing in amongst it)
I've known about the existence of the libraries mailing list for a while, and thought it might be something I'd sign up for at some point in the future.
The discussion around adding Foldable and Traversable to the Prelude - and the fact that it was a surprise to a lot of folks - got me thinking that I should probably sign up in order to keep up with these kind of changes / get a chance to have my say if I spot a problem with a proposal.
Does anyone on or familiar with the list know if it's the kind of list where casual, non-expert users are useful rather than background noise? Or am I conflating the libraries committee and the libraries mailing list?
On one hand, I wouldn't want to be a (potential) distraction.
On the other hand, I want to get in there to keep an eye on what is being proposed, mostly out of curiosity.
I also want to get in there for statistical reasons - I figure having more people active on the list might help with the mandate / marketing of the decisions the library committee makes.
Of course, that would fall to bits if the distribution of people for or against a proposal was correlated with the distribution of people too busy to sign up to another mailing list :)
Any info or thoughts would be appreciated.submitted by dalaing
[link] [2 comments]
Hi everyone, I would like to play with Buchi automata und would rather not start from scratch. Thanks.submitted by haskool
[link] [2 comments]
I'm trying to step through the ghc (Haskell Compiler) codebase, which is huge.
- What is the best way to step through a huge Haskell codebase ?
- What tools could help with this task ?
- Are there any tools like Visual Studio debugging ? (which I use when ramping up on huge C# projects)
- Is there a better way than to put 'trace' statements all over the code ?
It seems like 'trace' debugging and breaking things into tiny bits of functions is fine when I'm the one developing code bit by bit. But I find that model to be not that great when I want to understand some huge codebase and run the app, stop it at points and examine its behavior at runtime (like Visual Studio debugging).submitted by attilah
[link] [15 comments]