# News aggregator

### Looking for improvements/suggestions for a simple Tictactoe game!

Haskell on Reddit - Mon, 07/28/2014 - 6:00pm

I am looking for any and all feedback on improving the organization or style of the code to make it more idiomatic (code).

The things I'm considering doing are

• Making a dedicated Index type (instead of using Word) to constrain indices to only 3 values

• Making Board a newtype

• Removing StateT (I'm not exactly sure what benefits it brings other than making it explicit that there is state)

but I'm not sure if these are idiomatic either.

One question I have is why don't libraries use Word instead of Int when representing size or indices?

submitted by precalc
Categories: Incoming News

### New Functional Programming Job Opportunities

haskell-cafe - Mon, 07/28/2014 - 5:00pm
Here are some functional programming job opportunities that were posted recently: Senior Haskell Developer at Plow Technologies http://functionaljobs.com/jobs/8726-senior-haskell-developer-at-plow-technologies CTO / Tech Co-Founder at Capital Match http://functionaljobs.com/jobs/8725-cto-tech-co-founder-at-capital-match Cheers, Sean Murphy FunctionalJobs.com
Categories: Offsite Discussion

### Hac φ (Philadelphia): Oct 17-19, 2014

haskell-cafe - Mon, 07/28/2014 - 3:27pm
Categories: Offsite Discussion

### Awesome Machine Learning is missing Haskell libraries. BTW, what's the state of Haskell machine learning libraries compared to Julia ones? Is there a lot of development done?

Haskell on Reddit - Mon, 07/28/2014 - 2:13pm
Categories: Incoming News

### If-Then-Else Type Family

Haskell on Reddit - Mon, 07/28/2014 - 1:44pm

While designing a REST API client, I hit a problem where the data types I'm serializing to/from JSON differ only in a few fields for GET and POST requests. Rather than write two separate instances, I was wondering about using type families:

{-#LANGUAGE DataKinds #-} {-#LANGUAGE TypeFamilies #-} {-#LANGUAGE TypeOperators #-} module Main where data Method = GET | POST type family (m :: Method) := (n :: Method) :: Bool type instance GET := GET = True type instance GET := POST = False type instance POST := GET = False type instance POST := POST = True type family (b :: Bool) :? c :: * type instance True :? (x, y) = x type instance False :? (x, y) = y type x :. y = (x, y) data Resource (m :: Method) = Resource { param1 :: GET := m :? Int :. () , param2 :: POST := m :? Int :. () , param3 :: Int }

This is still very much a sketch, but I was wondering if there are any other examples of if-then-else computations at the type level (or if this is even a good idea at all).

EDIT: Actually, I'm not sure how to get this to work. When I try

get :: Resource GET get = Resource 1 () 0

I get the following type error:

Couldn't match type ()' with (('POST := 'GET) :? Int, ())' Expected type: (('POST := 'GET) :? Int) :. () Actual type: () In the second argument of Resource', namely ()' In the expression: Resource 1 () 0 In an equation for `get': get = Resource 1 () 0

EDIT: Fixed with help from jozefg: http://lpaste.net/108310

submitted by markandrus
Categories: Incoming News

### First-Class "Statements": IO as data

Haskell on Reddit - Mon, 07/28/2014 - 12:34pm
Categories: Incoming News

### Looking for Haskell Summer Course

Haskell on Reddit - Mon, 07/28/2014 - 12:30pm

I heard about a online summer school for the haskell programming language. AFAIK it is free. I just can't remember neither the name of the lecturer nor the course.

Does anybody know such a online cours/summer school for haskell this year or is able to give some hints?

Edit: Solved!

Categories: Incoming News

Haskell on Reddit - Mon, 07/28/2014 - 8:58am

Both mtl and extensible-effects try to provide a simple, type-safe, performant way of combining two Monads into 1 to get the effects of both, but most would a agree that they fall flat in one area or another. My question is: What would the API of the perfect solution look like if issues like performance were ignored?

submitted by sccrstud92
Categories: Incoming News

### Fusion of list functions

libraries list - Mon, 07/28/2014 - 8:03am
David, and other Haskell library folk You’ve been doing lots of work on making more Prelude functions fusible – thank you! This is really a library question, so I have not been following the details of the discussion, but I hope Edward and the Core Libraries Committee have been doing so; I’m cc’ing them. I’m more than happy to help with any questions if you all get stuck. Don’t forget to update the user manual http://www.haskell.org/ghc/docs/latest/html/users_guide/rewrite-rules.html#idp25099648 to say which functions are good producers/consumers. Actually, it might be better instead to state this in their Haddock comments, and remove or shrink this section of the user manual instead. It’s very hard to keep it up to date. I think it pre-dates Haddock. Many thanks. Simon From: Libraries [mailto:libraries-bounces< at >haskell.org] On Behalf Of Michael Snoyman Sent: 27 July 2014 06:08 To: Carter Schonwald Cc: Haskell Libraries Subject: Re: Am I missing something about unfo
Categories: Offsite Discussion

### Problem with existential type and instance.

haskell-cafe - Mon, 07/28/2014 - 6:46am
Hi, For code like below, how to make it compilable? data EventHandlers = forall m. MonadIO m => EventHandlers { onDeleteWindow :: Maybe (m ()) } instance Default EventHandlers where def = EventHandlers Nothing
Categories: Offsite Discussion

### Building list of functions in parallel.

Haskell on Reddit - Mon, 07/28/2014 - 2:54am

How do I go about building a list of functions in parallel? I have a bunch of entities that create a list of changes to be applied in sequence, but I want to generate the functions in parallel. Is there any easy way to force evaluation of all arguments required for a function? Does this have to be done on a case by case basis? What does a bang do in the following definition:

data Foo a b = Foo !(a -> b) submitted by Agitates
Categories: Incoming News

### High(low) performance recursion

Haskell on Reddit - Mon, 07/28/2014 - 1:41am

I have this recursive formula (Panjer recursion) that I need to implement efficiently in order to numerically approximate the probability distribution of the sum of iid random variables (I will now use Latex notation) :

s{r}=(1-p)\cdot\sum{r}{i=1}g{i}\cdot s{r-i}

I have implemented it in Haskell and Matlab but in both cases the code is too slow for (not so much) high 'r' due to the recursive nature of the problem.

I know that expressing recursive calls in terms of \textit{map} and \textit{fold} function would speed up the computation and make it even faster than a loop but I am stuck and I can not do better than this:

prob :: Int -> Float -> [Float] -> Float

prob r p gs = (1-p) * ( foldr (+) 0 [ g * ( prob (r-b) p gs) | (g,b) <- zip gs [1..r] ] )

Would you know how to improve it?

submitted by ceikit
Categories: Incoming News

### PPDP 2014: Program and 2nd Call for Participation

General haskell list - Sun, 07/27/2014 - 1:59pm
====================================================================== CALL FOR PARTICIPATION: PPDP 2014 16th International Symposium on Principles and Practice of Declarative Programming Canterbury, Kent, September 8-10, 2014 http://users-cs.au.dk/danvy/ppdp14/ co-located with LOPSTR 2014 24th International Symposium on Logic-Based Program Synthesis and Transformation Canterbury, Kent, September 9-11, 2014 http://www.iasi.cnr.it/events/lopstr14/ ====================================================================== Two weeks left for early registration (until August 8): http://www.cs.kent.ac.uk/events/2014/ppdp-lopstr-14/ A significant discount is available when registering to both events, especially as a student (until August 8). PPDP 2014 features * an invited talk by Roberto Giacobazzi, shared with LOPSTR: "Obscuring Code -- Unveiling and Veiling Information in Programs" * no fewer than 4 distilled tuto
Categories: Incoming News

### Exception in simple Pipes example

Haskell on Reddit - Sun, 07/27/2014 - 12:03pm

So I took the simple example of using Pipes to read from reddit (see here) and tried to turn it into a stand alone Producer.

It works but instead of just stopping when there's no more data coming in, it throws an exception. What am I missing?

{-# LANGUAGE OverloadedStrings #-} module Main where import Pipes as P import Pipes.HTTP import Pipes.ByteString as PB downloadRedditExample :: IO (Producer ByteString IO ()) downloadRedditExample = do req <- parseUrl "http://www.reddit.com/r/haskell.json" withManager defaultManagerSettings $\m -> withHTTP req m (return . responseBody) main :: IO () main = do redditPipe <- downloadRedditExample runEffect$ redditPipe >-> PB.stdout

Also on lpaste at http://lpaste.net/108221

submitted by hiptobecubic
Categories: Incoming News

### Intuition to understand poor man's concurrency

haskell-cafe - Sun, 07/27/2014 - 11:44am
Categories: Offsite Discussion

Haskell on Reddit - Sun, 07/27/2014 - 11:39am

Hey guys,

I've started a self-initiated project with Haskell in an effort to build an automated forex trading system based on the MACD indicator.

The Moving Average Convergence/Divergence (MACD) indicator is calculated as the difference between the 24-period and 52-period Exponential Moving Average (EMA) of a given currency pair, stock, etc. It's a useful tool for choosing entry/exit opportunities in the market. It analyzes the normal relationship between price and momentum, and identifies when that relationship has been temporarily broken to determine periods of bullish/bearish convergence/divergence. When a price/rate is lower than momentum suggests it should be, MACD issues a buy signal, as it is expected that the relationship between price/momentum will return to normal, and the quote will rise.

So here's my flowchart of how I imagine this system working:

http://imgur.com/84UtiZ9

I want to pull live quotes from an online database using a web query, run calculations on those quotes using Haskell, output those to Excel to construct conditionally-formatted tables, graphs, etc, and then have some sort of user interface that identifies buy/sell opportunities by displaying the currency pair and various statistics.

I don't even know if this is possible. I've only taken an intro to Comp Sci class and I'm clueless regarding the compatibility of Haskell with Excel. Yes, I could skip Haskell and do this entire thing in Excel, but that would defeat the purpose of the project, which is to get better at programming.

Phase 1: Haskell Functions. Here is what I have so far:

closing_prices = **HELP** --Can I import a list of live currency rates using a web query? I need a list to run the following functions on. --Simple Moving Average (SMA) calcSMA :: Int -> a calcSMA n = sum (take n closing_prices) / n --takes a number of periods (n), and a list closing prices (cp) --for the nth most recent periods, and returns a simple moving average --Exponential Moving Average (EMA) calcEMA :: Int -> a calcEMA n = (p * a) + (pEMA * (1 - a)) where p = head closing_prices a = 2 / (1 + n) pEMA = **HELP** --takes number of periods (n), current closing price (p), smoothing --factor (a), and the previous EMA (pEMA), and returns the current EMA ema24 = calcEMA 24 --24-period EMA ema52 = calcEMA 52 --52-period EMA calcMACD = subtract ema24 ema52

The functions are worthless without a continuously-updated list of exchange rates for a specified pair, say EUR/USD for example.

Also, since I need the EMA of the pair at the previous closing price to calculate the current EMA, I don't think a recursive function would work, and I don't really know where to go with this function next.

Any help would be greatly appreciated.

submitted by Mister_Balloon_Hands
Categories: Incoming News

### Seeking feedback on a web asset pipeline library

Haskell on Reddit - Sun, 07/27/2014 - 10:25am

I've been writing a library to help with compiling and serving web assets, which is more or less ready to be used: https://github.com/hdgarrood/herringbone

If you are doing web stuff in Haskell, I'd like feedback. Is this the kind of thing you can see yourself using? If not, why not? Would you have designed it differently? Does the README tell you what you want to know? and so on.

submitted by hdgarrood
Categories: Incoming News

### Reading files from the /proc filesystem

Haskell on Reddit - Sun, 07/27/2014 - 7:31am
Categories: Incoming News

### Yesod Web Framework: Reading files from the proc filesystem

Planet Haskell - Sun, 07/27/2014 - 4:50am

I was stumped by this one myself for a bit today, so I thought writing it up in a blog post would be a good way to make sure (1) I don't forget this little fact, and (2) hopefully the next person doesn't need to puzzle over this as long as I did. Let's say you want to read the contents of a file in the proc filesystem, such as /proc/uptime. There are many ways to do that in Haskell. Let's ignore any streaming data framework for the moment, and instead focus on just the "string-like" types: String and strict/lazy ByteString/Text. Here's a little program that tries all of them out:

import qualified Data.ByteString as S import qualified Data.ByteString.Lazy as L import qualified Data.Text.IO as T import qualified Data.Text.Lazy.IO as TL test :: Show a => String -> (FilePath -> IO a) -> IO () test name reader = do contents <- reader "/proc/uptime" putStrLn $name ++ ": " ++ show contents main :: IO () main = do test "String " readFile test "strict ByteString" S.readFile test "lazy ByteString " L.readFile test "strict Text " T.readFile test "lazy Text " TL.readFile Given that the uptime file is just simple ASCII data, you'd probably assume (like I did) that all of these will produce the same result. In fact, that's not the case. On my system, the results are: String : "60740.70 136144.86\n" strict ByteString: "" lazy ByteString : "60740.70 136144.86\n" strict Text : "60740.70 136144.86\n" lazy Text : "60740.70 136144.86\n" Strict ByteString reading is returning an empty value! Why is this happening? It's actually quite easy to see once you throw in two new pieces of information. First, let's look at the implementation of Data.ByteString.readFile: readFile :: FilePath -> IO ByteString readFile f = bracket (openBinaryFile f ReadMode) hClose (\h -> hFileSize h >>= hGet h . fromIntegral) Notice how we allocate a buffer exactly the right size to read in the entire contents of the file. We don't do this with any of the file reading functions. For the lazy variants, we don't want to read the entire file into memory at once. And for strict Text, knowing the size of the file doesn't tell us the size of the buffer we need to allocate, due to variable length encoding. So this nifty optimization only applies to strict ByteStrings. Now piece of data number two:$ ls -l /proc/uptime -r--r--r-- 1 root root 0 Jul 27 13:56 /proc/uptime

Huh, the file is empty! As is well documented, virtually every file in the proc filesystem is listed as empty, and the contents are generated on demand by the kernel.

So how do you read the file contents into a strict ByteString? There are actually plenty of approaches that work. In my case, I ended up just writing a helper function using conduit:

localReadFile fp = IO.withBinaryFile fp IO.ReadMode $\h -> sourceHandle h$\$ foldC

But probably the simplest thing to do is to just convert a lazy ByteString into a strict ByteString, e.g. fmap L.toStrict . L.readFile.

Categories: Offsite Blogs

### Converting Make to Shake

Haskell on Reddit - Sun, 07/27/2014 - 3:45am
Categories: Incoming News