I was watching the Udacity course on "Design of Computer Programs" and thought it would be kindof fun to redo the stuff in Haskell.
So I more or less 1:1 the python stuff there into Haskell (you can find it here: Gist )
Now to get the stats for the hand-ranks I thought it a good idea to draw 1mio. random hands and classify them using this function:randomStats :: Int -> IO [(Text, Float)] randomStats n = percentOf . sortWith (negate . snd) . M.toList <$> drawHands n M.empty where drawHands n' m = if n' == 0 then return m else do !r <- classifyRank . head <$> randomHands defaultDeck 1 let m' = M.insertWith (+) r 1 m drawHands (n'-1) m' percentOf :: [(Text, Int)] -> [(Text, Float)] percentOf = map (\ (x,c) -> (x, 100 * fromIntegral c / fromIntegral n))
Where this is using Data.Map.Strict and Data.Text.
Now as far as I understand the strict maps they should eval the keys into WHNF - but when I remove the bang from r I can watch the program eating memory till I run out of RAM/Swap ;) ... with it it runs fine (not really quick but ok)
Can someone explain to me why? Should not insertWith do basically the same?
Thank you for your helpsubmitted by CKoenig
[link] [8 comments]
Haskell Application Engineer - Telecommute - anywhere in North America
Hi everyone. We have a new opening on the FP Complete team for a Haskell programmer with a lot of initiative and the desire to interact directly with business customers.
This job involves not only application design and coding, but also lots of communication with customers (and potential customers): to determine their broad and immediate needs, identify an initial problem that we can solve, understand their urgency, budget, and decision-making process, and develop proposals on how new and existing code can be used to solve the problem. And of course, ultimately, to design and implement the solution -- either solo or with colleagues.
This position requires a demonstrated ability to write and deliver working applications using Haskell or another modern (preferably functional) language. You must have excellent communication skills in English, and be able to talk to people and figure out what they want. We will consider applications from less advanced programmers if they have a willingness to learn and very strong customer-facing skills.
This is a near-full-time contractor position, with fairly flexible hours, intended to last long-term. You'll work mostly from home (anywhere in North America) via Internet, and may occasionally travel to meet with your users in person.
You must have a history of taking initiative, and be able to deliver on projects without lots of supervision. You must have a demonstrated ability to learn new languages, libraries, and tools, figure out and document people’s needs and requirements, and turn requirements into detailed solution designs.
If you have some understanding of quantitative financial analysis, or similar kinds of data analysis, that's a big plus. If you have experience driving successful project approvals, another big plus.
If you are a good programmer with a head for business or sales, this might be a great fit. Applicants for previous positions are also welcome to re-apply.
To apply, email me at email@example.com or PM me. Include a resume or C.V., and links to cool things you have done, ideally including code projects.submitted by FPguy
[link] [3 comments]
So, as many of you know, GHCJS is pretty hard to get set up.
Clearly, some people have gotten GHCJS set up, and some will be in a VM image.
So, I'm requesting that someone share that image.
I've tried the Vagrant images, but they haven't worked for me, even the pre-built ones. They don't seem to have been updated for quite some time, and I get errors running vagrant up with them.
GHCJS would be great if it were easy, but in the meantime, I think having a good starter VM floating around would be a good solution.
That said, if someone has a good guide of how to get the vagrant images up and working, that would be great. But would much prefer a VM image I can just download and run.submitted by jmite
[link] [14 comments]
Can you recommend reliable open-source Snap projects?
I have some knowledge of Haskell (mostly gained from Learn You a Haskell), and I have experience creating web apps with Django.
The idea is to see good examples of web development using Haskell that we can learn from. (The focus of my interest would be project structuring, testing and session handling.)submitted by danbal
[link] [6 comments]
I made a function in Haskell that takes in a number and returns a list of integers from 1 to that number.gen x = [1..x] gen 4 -> [1, 2, 3, 4]
As I was learning about the monads I noticed that I could bind a list into this function as it has the type of (a -> m a).[2, 3, 6, 1, 4] >>= gen -> [1, 2, 1, 2, 3, 1, 2, 3, 4, 5, 6, 1, 1, 2, 3, 4]
Then I wanted to write a function that would reverse the (>>= gen) and i came up with this function.revgen (x:xs) = case (null xs) of False -> case ((head xs) - x) of 1 -> 1 + revgen xs otherwise -> 0 : revgen xs True -> 1 : 
But it doesn't work, I think because of the revgen returning both numbers and lists. But I can't come up with a way to do this any other way with one function. Also the nested cases look ugly as hell but I quess they work as intented because at least it compiles.submitted by SpacemanInBikini
[link] [10 comments]
I apologize if this is way off topic, but I've been poring over this for a while and I think this might be a good place to ask: has there been any research on 'inverse types'? Either in Haskell or in general.
I'm trying to learn more about abstract algebra and algebraic data types, and from what I can tell the types form a semiring (though if there's a more accurate/complete structure please let me know!). What I'm wondering is if it's possible to extend this semiring to a full ring, or even a field. I've heard of a Grothendieck construction for groups and suspect it is also applicable to semirings, but I haven't really investigated that area very much.
Additionally I can't seem to find any intuitive expression of the additive or multiplicative inverse of a type offhand, but I'm curious if there even is one. Additive inverses seem to make a little bit of sense perhaps in a resource consumption sort of way, but it's shaky at best. And I have no idea what the reciprocal of a type would represent either, though I did see a 'quotient type' mentioned at the end of the clowns and jokers paper.submitted by asampson
[link] [30 comments]
I have:type family Flip a where Flip (a -> b) = b -> a > :kind! Flip (Int -> Bool) Flip (Int -> Bool) :: * = Bool -> Int
but it doesn't work for unboxed values:> Flip (Int# -> Bool) Flip (Int# -> Bool) :: * = Flip (Int# -> Bool) > import Data.Type.Equality > :t Refl :: (Flip (Int# -> Bool) :~: (Bool -> Int#)) <interactive>:1:1: Warning: Couldn't match type ‘Flip (Int# -> Bool)’ with ‘Bool -> Int#’ Expected type: Flip (Int# -> Bool) :~: (Bool -> Int#) Actual type: (Bool -> Int#) :~: (Bool -> Int#) In the expression: Refl :: Flip (Int# -> Bool) :~: (Bool -> Int#) Refl :: (Flip (Int# -> Bool) :~: (Bool -> Int#)) :: (Bool -> Int#) :~: (Bool -> Int#)
Is there any way to fix that?submitted by haskellthrowaway
[link] [8 comments]