News aggregator

project compile with multi-versions of alex

haskell-cafe - Mon, 01/18/2016 - 2:48am
Hi Cafe, I have a Haskell project which has ~90 dependencies (transitively) and is managed with plain cabal (w/o stackage, etc.). I try to keep it compile with a few latest releases of GHC (so right now 7.8.4, 7.10.1, 7.10.2 and 7.10.3). It was tractable with conditionals in the cabal config file with minor annoyance. But recently I found this issue:language-c-quote-0.11.3 does not compile with alex 3.1.5 [1]. I was wondering if I should also allow a few versions of executables, like alex, happy, etc (I can see though it will be a huge pain); or should I force all users to use the latest versions of them (I don't know if they are compatible with old ghc versions)? What's the common practice for other projects? Any hints? What should I write in my cabal config? Thanks, Zilin [1]https://github.com/mainland/language-c-quote/issues/57 _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion

How to build Haddock git master?

Haskell on Reddit - Sun, 01/17/2016 - 11:34pm

I think I need to patch Haddock quite a lot to fully realize my ideas for this theme. I'd like to use the Haddock's git master as the base so that I can hopefully make a pull request, but it seems to require latest GHC beta, and there are no instructions on how to get it.

submitted by lamefun
[link] [2 comments]
Categories: Incoming News

Haskell for Finance resources

Haskell on Reddit - Sun, 01/17/2016 - 11:17pm

I'm looking for resources that discuss Haskell in the context of finance. A few that I know about:

This list is fairly limited. Are there any other resources that are interesting to list?

submitted by stasiana
[link] [9 comments]
Categories: Incoming News

lts-4 with aeson-0.10 is being discontinued, lts-5 will use aeson-0.9

Haskell on Reddit - Sun, 01/17/2016 - 7:56pm

Thank you for this discussion the other day. What I saw there confirmed the general consensus among stackage curators about how to approach this situation.

The switch back to aeson-0.9 has a few bumps, tracked here. I'd like to thank the package authors that have the patience to work with us on this.

Tonight lts-4.2 will be released. After that, we don't anticipate any updates to the lts-4 series. Normally, an LTS is supported for a minimum of 3 months, but we feel this exception is appropriate. Next week, lts-5.0 will be released, and we hope that it will help prevent issues like this one.

submitted by drb226
[link] [17 comments]
Categories: Incoming News

Statically linking Haskell executables and glibc

Haskell on Reddit - Sun, 01/17/2016 - 3:23pm

When I compile a simple application with ghc -static -optl-static -optl-pthread, I get a warning: "Using dlopen in statically linked applications requires at runtime the shared libraries from the glibc version used for linking". (There are more similar warnings if I use network package). Makes sense: statically linked glibc is not really supported. The question is, how to link statically everything except glibc?

submitted by DravRorn
[link] [6 comments]
Categories: Incoming News

Type inference regression with monad-control

Haskell on Reddit - Sun, 01/17/2016 - 1:55pm

So here's a thing that's been confusing me today. I resurrected some older code and noticed that it no longer typechecks. It used to at some point, but time makes all types more ambiguous, it seems. Reducing it to the basics, I'm doing something like this:

main :: IO () main = do _ <- flip runStateT (0 :: Int) $ do control $ \run -> liftIO $ catch (putStrLn "Hello World" >> run (modify' (+ 10) >> return (Just (10 :: Int)))) (\(_ :: SomeException) -> run (modify' (+ 10) >> return Nothing)) return ()

The usual monad-control magic to tunnel my transformer stack through a IO function. Notice the two invocation of run for both the normal and failure case. This works just fine. Here's a slightly more complicated variation:

withSomething :: (MonadBaseControl IO m) => (Int -> m a) -> m (Maybe a) withSomething f = control $ \run -> liftIO $ catch (run $ Just <$> f 10) (\(_ :: SomeException) -> run $ return Nothing)

The return type here depends on the free type variables from the argument function. This no longer typechecks:

Couldn't match type ‘StM m (Maybe a)’ with ‘StM m (Maybe a0)’ NB: ‘StM’ is a type function, and may not be injective The type variable ‘a0’ is ambiguous Expected type: IO (StM m (Maybe a)) Actual type: IO (StM m (Maybe a0))

I swear I've done this exact thing all the time and it always worked. On GHC 7.8 and some older version of monad-control. Being a bit more explicit with the types and annotating the failure case which seems to trouble GHC:

withSomething :: forall a m. (MonadBaseControl IO m) => (Int -> m a) -> m (Maybe a) withSomething f = control $ \run -> liftIO $ catch (run $ Just <$> f 10) (\(_ :: SomeException) -> run $ return (Nothing :: Maybe a))

...and it works again. Hm. I don't suspect the issue is GHC 7.10, but the changelog of monad-control indicates something that might've broken it:

Switch the associated data types StT and StM to associated type synonyms. This is an API breaking change.

I don't really know what that's about but that change has certainly happened in the meantime. I can fix my problem by being a bit more explicit with my type annotations, but I'm a bit confused why it's suddenly no longer possible to just infer the types. They strike me as rather unambiguous. If anybody has a handle on what the issue is, I'd be curious to know ;-)

submitted by SirRockALot1
[link] [3 comments]
Categories: Incoming News

Is there a way to have a function that returns a random number?

Haskell on Reddit - Sun, 01/17/2016 - 12:48pm

I understand why random numbers are so wonky in Haskell. They're considered 'impure' and are thus put in the IO monad. Is there a way to write a function that will return a random number though?

submitted by Grantselrich
[link] [27 comments]
Categories: Incoming News

wren gayle romano: A week of "P"s

Planet Haskell - Sun, 01/17/2016 - 12:34pm

The next week+ I'll be in St. Petersburg Florida for PEPM, PADL, POPL, PPS, and PPAML PI (also CPP and OBT). Would've mentioned it sooner, but it's a bit of a last minute thing. I love reconnecting with old friends and meeting new folks, so feel free to come say hi. If you want to meet up for dinner or such, leave a comment with when/where to find you, or just look for the tall gal with the blue streak in her hair.



comments
Categories: Offsite Blogs

Idris compile checked printf, possible in Haskell soon? (with TypeInType coming up, etc)

Haskell on Reddit - Sun, 01/17/2016 - 11:52am

With the new TypeInType extension coming up in GHC 8.0, and a lot of work going into getting dependent type features in Haskell, I was wondering how far we are from something like this https://gist.github.com/puffnfresh/11202637, which is done in Idris (explanation of the code here https://www.youtube.com/watch?v=fVBck2Zngjo)?

A TL;DR of the link: It's a compile time checked version of printf, where the current Text.Printf gives runtime exceptions on wrong usage, the idris version is able to catch this beforehand.

submitted by Tehnix
[link] [39 comments]
Categories: Incoming News

Gabriel Gonzalez: How to contribute to the Haskell ecosystem

Planet Haskell - Sun, 01/17/2016 - 11:40am

I wanted to share a few quick ways that beginning Haskell programmers can contribute to the Haskell ecosystem. I selected these tasks according to a few criteria:

  • They are fun! These tasks showcase enjoyable tricks
  • They are easy! They straightforwardly apply existing libraries
  • They are useful! You can probably find something relevant to your project

For each task I'll give a brief end-to-end example of what a contribution might look like and link to relevant educational resources.

This post only assumes that you have the stack build tool installed, which you can get from haskellstack.com. This tool takes care of the rest of the Haskell toolchain for you so you don't need to install anything else.

Contribution #1: Write a parser for a new file format

Writing parsers in Haskell is just about the slickest thing imaginable. For example, suppose that we want to parse the PPM "plain" file format, which is specified like this [Source]:

Each PPM image consists of the following:

  1. A "magic number" for identifying the file type. A ppm image's magic number is the two characters "P3".
  2. Whitespace (blanks, TABs, CRs, LFs).
  3. A width, formatted as ASCII characters in decimal.
  4. Whitespace.
  5. A height, again in ASCII decimal.
  6. Whitespace.
  7. The maximum color value (Maxval), again in ASCII decimal. Must be less than 65536 and more than zero.
  8. A single whitespace character (usually a newline).
  9. A raster of Height rows, in order from top to bottom. Each row consists of Width pixels, in order from left to right. Each pixel is a triplet of red, green, and blue samples, in that order. Each sample is represented as an ASCII decimal number.

The equivalent Haskell parser reads almost exactly like the specification:

{-# LANGUAGE OverloadedStrings #-}

import Control.Monad (guard)
import Data.Attoparsec.Text

data PPM = PPM
{ width :: Int
, height :: Int
, maximumColorValue :: Int
, image :: [[RGB]]
} deriving (Show)

data RGB = RGB
{ red :: Int
, green :: Int
, blue :: Int
} deriving (Show)

ppm3 :: Parser PPM
ppm6 = do
"P3"
skipMany1 space
w <- decimal
skipMany1 space
h <- decimal
skipMany1 space
maxVal <- decimal
guard (maxVal < 65536)
space
let sample = do
lo <- decimal
skipMany1 space
return lo
let pixel = do
r <- sample
g <- sample
b <- sample
return (RGB r g b)

rows <- count h (count w pixel)
return (PPM w h maxVal rows)

We can try to test our parser out on the following example file:

$ cat example.ppm
P6
4 4
255
0 0 0 100 0 0 0 0 0 255 0 255
0 0 0 0 255 175 0 0 0 0 0 0
0 0 0 0 0 0 0 15 175 0 0 0
255 0 255 0 0 0 0 0 0 255 255 255

We don't even have to compile a program to test our code. We can load our code into the Haskell REPL for quick feedback on whether or not our code works:

$ stack ghci attoparsec --resolver=lts-3.14
...
Prelude> :load ppm.hs
[1 of 1] Compiling Main ( ppm.hs, interpreted )
Ok, modules loaded: Main.
*Main> txt <- Data.Text.IO.readFile "example.ppm"
*Main> parseOnly ppm3 txt
Right (PPM {width = 4, height = 4, maximumColorValue = 255,
image = [[RGB {red = 0, green = 0, blue = 0},RGB {red = 100,
green = 0, blue = 0},RGB {red = 0, green = 0, blue = 0},RGB
{red = 255, green = 0, blue = 255}],[RGB {red = 0, green =
0, blue = 0},RGB {red = 0, green = 255, blue = 175},RGB {red
= 0, green = 0, blue = 0},RGB {red = 0, green = 0, blue = 0
}],[RGB {red = 0, green = 0, blue = 0},RGB {red = 0, green =
0, blue = 0},RGB {red = 0, green = 15, blue = 175},RGB {red
= 0, green = 0, blue = 0}],[RGB {red = 255, green = 0, blue
= 255},RGB {red = 0, green = 0, blue = 0},RGB {red = 0, gre
en = 0, blue = 0},RGB {red = 255, green = 255, blue = 255}]]
})

Works like a charm!

You can very quickly get your hands dirty with Haskell by writing a parser that converts a file format you know and love into a more structured data type.

To learn more about parser combinators in Haskell, I highly recommend this "functional pearl":

... as well as this attoparsec tutorial:

To see a "long form" example of attoparsec, check out this HTTP request parser written using attoparsec:

I use "long form" in quotes because the entire code is around 60 lines long.

Contribution #2: Write a useful command-line tool

Haskell's turtle library makes it very easy to write polished command-line tools in a tiny amount of code. For example, suppose that I want to build a simple comand-line tool for managing a TODO list stored in a todo.txt file. First I just need to provide a subroutine for displaying the current list:

{-# LANGUAGE OverloadedStrings #-}

import Turtle

todoFile = "TODO.txt"

todoItem = d%": "%s

display :: IO ()
display = sh (do
(n, line) <- nl (input todoFile)
echo (format todoItem n line) )

... a subroutine for adding an item to the list:

add :: Text -> IO ()
add txt = runManaged (do
tempfile <- mktempfile "/tmp" "todo"
output tempfile (input todoFile <|> pure txt)
mv tempfile todoFile )

... and a subroutine for removing an item from the list:

remove :: Int -> IO ()
remove m = runManaged (do
tempfile <- mktempfile "/tmp" "todo"
output tempfile (do
(n, line) <- nl (input todoFile)
guard (m /= n)
return line )
mv tempfile todoFile )

... then I can just wrap them in a command line API. I create a command line parser that runs display by default if the command line is empty:

parseDisplay :: Parser (IO ())
parseDisplay = pure display

... then a command line parser for the add subcommand:

parseAdd :: Parser (IO ())
parseAdd =
fmap add
(subcommand "add" "Add a TODO item"
(argText "item" "The item to add to the TODO list") )

... and a command line parser for the remove subcommand:

parseRemove :: Parser (IO ())
parseRemove =
fmap remove
(subcommand "rm" "Remove a TODO item"
(argInt "index" "The numeric index of the TODO item to remove") )

Finally, I combine them into a single composite parser for all three subcommands:

parseCommand :: Parser (IO ())
parseCommand = parseDisplay <|> parseAdd <|> parseRemove

... and run the parser:

main = do
command <- options "A TODO list manager" parseCommand
exists <- testfile todoFile
when (not exists) (touch todoFile)
command

... and I'm done! That's the full program:

{-# LANGUAGE OverloadedStrings #-}

import Turtle

todoFile = "TODO.txt"

todoItem = d%": "%s

display :: IO ()
display = sh (do
(n, line) <- nl (input todoFile)
echo (format todoItem n line) )

add :: Text -> IO ()
add txt = runManaged (do
tempfile <- mktempfile "/tmp" "todo"
output tempfile (input todoFile <|> pure txt)
mv tempfile todoFile )

remove :: Int -> IO ()
remove m = runManaged (do
tempfile <- mktempfile "/tmp" "todo"
output tempfile (do
(n, line) <- nl (input todoFile)
guard (m /= n)
return line )
mv tempfile todoFile )

parseDisplay :: Parser (IO ())
parseDisplay = pure display

parseAdd :: Parser (IO ())
parseAdd =
fmap add
(subcommand "add" "Add a TODO item"
(argText "item" "The item to add to the TODO list") )

parseRemove :: Parser (IO ())
parseRemove =
fmap remove
(subcommand "rm" "Remove a TODO item"
(argInt "index" "The numeric index of the TODO item to remove") )

parseCommand :: Parser (IO ())
parseCommand = parseDisplay <|> parseAdd <|> parseRemove

main = do
command <- options "A TODO list manager" parseCommand
exists <- testfile todoFile
when (not exists) (touch todoFile)
command

We can compile that program into an native binary on any platform (i.e. Windows, OS X, or Linux) with a fast startup time:

$ stack build turtle --resolver=lts-3.14
$ stack ghc --resolver=lts-3.14 -- -O2 todo.hs

... and verify that the program works:

$ ./todo add "Brush my teeth"
$ ./todo add "Shampoo my hamster"
$ ./todo
0: Brush my teeth
1: Shampoo my hamster
$ ./todo rm 0
$ ./todo
0: Shampoo my hamster

The program also auto-generates the usage and help information:

$ ./todo --help
A TODO list manager

Usage: todo ([add] | [rm])

Available options:
-h,--help Show this help text

Available commands:
add
rm
$ ./todo add
Usage: todo add ITEM
$ ./todo rm
Usage: todo rm INDEX

Amazingly, you can delete all the type signatures from the above program and the program will still compile. Try it! Haskell's type inference and fast type-checking algorithm makes it feel very much like a scripting language. The combination of type inference, fast startup time, and polished command line parsing makes Haskell an excellent choice for writing command-line utilities.

You can learn more about scripting in Haskell by reading the turtle tutorial, written for people who have no prior background in Haskell programming:

Contribution #3: Client bindings to a web API

Haskell's servant library lets you write very clean and satisfying bindings to a web API. For example, suppose that I want to define a Haskell client to to the JSONPlaceholder test API. We'll use two example endpoints that the API provides.

A GET request against the /posts endpoint returns a list of fake posts:

[
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat ..."
"body": "quia et suscipit\nsuscipit ..."
},
{
"userId": 1,
"id": 2,
"title": "qui est esse",
"body": "est rerum tempore vitae\nsequi ..."
},
...

... and a POST request against the same endpoint accepts a list of posts and returns them back as the response.

To write a client binding to this API, we just need to define a record representing APost:

data APost = APost
{ userId :: Int
, id :: Int
, title :: Text
, body :: Text
} deriving (Show, Generic, FromJSON, ToJSON)

The last line instructs the Haskell compiler to auto-derive conversion functions between APost and JSON.

Now we just encode the REST API as a type:

-- We can `GET` a list of posts from the `/posts` endpoint
type GetPosts = "posts" :> Get '[JSON] [APost]

-- We can `POST` a list of posts to the `/posts` endpoint
-- using the request body and get a list of posts back as
-- the response
type PutPosts = ReqBody '[JSON] [APost] :> "posts" :> Post '[JSON] [APost]

type API = GetPosts :<|> PutPosts

... and then the compiler will "automagically" generate API bindings:

getPosts :<|> putPosts =
client (Proxy :: Proxy API) (BaseUrl Http "jsonplaceholder.typicode.com" 80)

Now anybody can use our code to GET or POST lists of posts. We can also quickly test out our code within the Haskell REPL to verify that everything works:

$ stack ghci servant-server servant-client --resolver=lts-3.14
ghci> :load client.hs
[1 of 1] Compiling Main ( httpbin.hs, interpreted )
Ok, modules loaded: Main.
*Main> import Control.Monad.Trans.Either as Either
*Main Either> -- Perform a `GET` request against the `/posts` endpoint
*Main Either> runEitherT getPosts
Right [APost {userId = 1, id = 1, title = "sunt aut facere ...
*Main Either> -- Perform a `POST` request against the `/posts` endpoint
*Main Either> runEitherT (putPosts [APost 1 1 "foo" "bar"])
Right [APost {userId = 1, id = 1, title = "foo", body = "bar"}]

Here's the full code with all the extensions and imports that enable this magic:

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}

import Data.Aeson (FromJSON, ToJSON)
import Data.Text (Text)
import GHC.Generics (Generic)
import Servant
import Servant.Client

data APost = APost
{ userId :: Int
, id :: Int
, title :: Text
, body :: Text
} deriving (Show, Generic, FromJSON, ToJSON)

type GetPosts = "posts" :> Get '[JSON] [APost]
type PutPosts = ReqBody '[JSON] [APost] :> "posts" :> Post '[JSON] [APost]
type API = GetPosts :<|> PutPosts

getPosts :<|> putPosts =
client (Proxy :: Proxy API) (BaseUrl Http "jsonplaceholder.typicode.com" 80)

To learn more about how this works, check out the servant tutorial here:

Note that servant is both a client and server library so everything you learn about auto-generating client side bindings can be reused to auto-generate a server, too!

To see a more long-form example of bindings to the Google Translate API, check out this code:

Conclusion

Suppose that you write up some useful code and you wonder: "What's next? How do I make this code available to others?". You can learn more by reading the stack user guide which contains complete step-by-step instructions for authoring a new Haskell project, including beginning from a pre-existing project template:

Categories: Offsite Blogs

[Code Review] Advent of Code solutions

Haskell on Reddit - Sun, 01/17/2016 - 11:31am

I used Advent of Code as an opportunity to learn and practice more Haskell. Please take a look through my solutions and open issues for any advice you have. Thanks!

https://github.com/thejohnfreeman/advent-2015

submitted by therealjohnfreeman
[link] [4 comments]
Categories: Incoming News

Server-side data binding solution (template engine) for servant

Haskell on Reddit - Sun, 01/17/2016 - 2:55am

We need a template engine for developing a web application on top of haskell servant + postgresql.

The templates syntax should minimally distort the HTML, because the HTML is provided from the outside and the HTML surely will be changed quite often. Adding some extra tags to bind data is ok. Putting the whole HTML into the, say, Sheakspeare engine is not OK, cause third party developers have no idea about this engine.

I tried Heist that is match for the first sight, but the using it in Haskell looks scary. I'm still don't understand how to use it outside the Snap. Is it true that in fact SQL queries should be performed from inside the templates, i.e. "splices", i.t there is no way to perform something like

html <- renderTemplate theTemplate theDataBound

And receiving values are not pure, so integration with servant will be lame anyway.

What else can I use? What do I miss?

I'm about to give it up and using client-side data binding or XSLT.

submitted by voidlizard
[link] [18 comments]
Categories: Incoming News

CfP: Workshop on Program Transformation for Programmability in Heterogeneous Architectures (Co-located with CGO16); Deadline Jan 22 [Extended]

General haskell list - Sat, 01/16/2016 - 10:25pm
[Apologies if you receive multiple copies of this announcement.] ********************************************************************************* PROHA 2016, CALL FOR PAPERS -- Deadline extension First Workshop on Program Transformation for Programmability in Heterogeneous Architectures http://goo.gl/RzGbzY Barcelona, 12th March 2016, in conjunction with the CGO'16 Conference ********************************************************************************* Important Dates: Paper submission deadline: 22 January 2016 23:59 (UTC) [Extended] Author notification: 5 February 2016 Final manuscript due: 26 February 2016 Scope: Developing and maintaining high-performance applications and libraries for heterogeneous architectures is a difficult task, usually requiring code transformations performed by an expert. Tools assisting in and, if possible, automating such transformations are of course of great interest. However, such tools require significant knowledge and reasoning capabilities. For example, th
Categories: Incoming News

Magnus Therning: Free play, part three

Planet Haskell - Sat, 01/16/2016 - 6:00pm

The code in the previous post can do with a bit of cleaning up. I start with introducing a type class for an API that can be run

class RunnableF f where runOp :: f a -> IO a

and a function that actually runs iteFile

runF :: (RunnableF o) => Free o a -> IO a runF = foldFree runOp

A coproduct (Sum) of two runnable APIs can itself be runnable

instance (RunnableF f, RunnableF g) => RunnableF (Sum f g) where runOp (InL op) = runOp op runOp (InR op) = runOp op

After this all I have to do is to move the guts of runSimpleF and runLogging into implementations for SimpleFil and LogF respectively

instance RunnableF SimpleFileF where runOp (LoadFile fp f') = liftM f' $ readFile fp runOp (SaveFile fp d r) = writeFile fp d >> return r instance RunnableF LogF where runOp (Log s a)= putStrLn s >> return a

The rest is left as is. Running now looks like this

> :! cat test.txt Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. > runF $ withSimpleFile (map toUpper) "test.txt" > :! cat test.txt_new LOREM IPSUM DOLOR SIT AMET, CONSECTETUR ADIPISCING ELIT. DONEC A DIAM LECTUS. SED SIT AMET IPSUM MAURIS. MAECENAS CONGUE LIGULA AC QUAM VIVERRA NEC CONSECTETUR ANTE HENDRERIT. > runF $ foldFree loggingSimpleFileI $ withSimpleFile (map toLower) "test.txt" ** load file test.txt ** save file test.txt_new > :! cat test.txt_new lorem ipsum dolor sit amet, consectetur adipiscing elit. donec a diam lectus. sed sit amet ipsum mauris. maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. What else?

With these changes it becomes slightly esier to create new basic API types. but there are still a few things I think could be useful:

  • More generic decorators. logSimpleFileI is tied to decorating only SimpleFileF. I’m fairly sure this could be dealt with by a type class LoggableF and have APIs implement it. I also think there’s a rather natural implementation of LoggableF for Sum f g.
  • Combining decorators (and other interpreters). I’m guessing this is what John refers to as “generalizing interpreters.”
  • Combining APIs. I’d prefer making small APIs of related operations, but then that also means I need a nice way of combining APIs. I had a go at using FreeT but simply gave up on bending the types to my will. In any case I’m not completely sure that a stack of various FreeT is a good direction to go.
Categories: Offsite Blogs

Could not find module ‘Distribution.Simple’ on spacemacs + stack setup

Haskell on Reddit - Sat, 01/16/2016 - 9:29am

This is from a fresh (1-week-old) Arch install.

It says:

Setup.hs:1:18: Could not find module ‘Distribution.Simple’ …

It is a member of the hidden package ‘Cabal-1.22.6.0@Cabal_HTEBgMfq9lTDv7Mrzzz2mb’.

It is a member of the hidden package ‘Cabal-1.22.5.0@Cabal_3ux67khMI118y6VpwrFnXN’.

Use -v to see a list of the files searched for.

Compilation failed.

Any clues? I do not have a Cabal executable on my path. Stack and ghc-mod are the latest git versions.

Also, is it necessary to update the .cabal file every time I add new packages tostack.yaml? It seems stupid.

submitted by octatoan
[link] [5 comments]
Categories: Incoming News

What is Type-In-Type?

Haskell on Reddit - Sat, 01/16/2016 - 5:30am

It seems that the extension called -XTypeInType will possibly be implemented by GHC 8.0.

I heard this recently. I thought I could find some introduction with Google, but I didn't.

What I think I know is something like "now, with TypeInType, 2 layers are enough.". I know the documentation is not done yet, but there should at least be some proposal or discussion. What it is designed for?

submitted by RnMss
[link] [10 comments]
Categories: Incoming News

What sort of candidates are shops like Jane Street looking for for summer internships?

Haskell on Reddit - Sat, 01/16/2016 - 5:19am

Currently looking around for summer internships. Derfinitely considering applying to Jane Street, but I wanted to get some background and see if I'm actually the type of candidate they might accept. Also, if anyone knows any, I'd love to know of other functional-programming heavy shops that are hiring summer interns! Thanks!

EDIT: I'm an undergrad

submitted by fruitbooploops
[link] [25 comments]
Categories: Incoming News

How to understand Haskell's permutations implementation

Haskell on Reddit - Sat, 01/16/2016 - 4:55am

I have been working through some programming exercises recently (adventofcode) in an effort to learn Haskell. One exercise required finding different permutations of a list of items. I tried for a while and eventually came up with a solution. Afterwards I noticed that Data.List has its own permutations implementation:

-- | The 'permutations' function returns the list of all permutations of the argument. -- -- > permutations "abc" == ["abc","bac","cba","bca","cab","acb"] permutations :: [a] -> [[a]] permutations xs0 = xs0 : perms xs0 [] where perms [] _ = [] perms (t:ts) is = foldr interleave (perms ts (t:is)) (permutations is) where interleave xs r = let (_,zs) = interleave' id xs r in zs interleave' _ [] r = (ts, r) interleave' f (y:ys) r = let (us,zs) = interleave' (f . (y:)) ys r in (y:us, f (t:y:us) : zs)

Here is my solution for comparison.

permutations :: [a] -> [[a]] permutations [] = [[]] permutations (x:xs) = foldr (++) [] (map (interleave [] x) (permutations xs)) where interleave :: [a] -> a -> [a] -> [[a]] interleave xs x [] = [xs ++ [x]] interleave xs x (y:ys) = (xs ++ (x:y:ys)) : (interleave (xs ++ [y]) x ys)

To explain how my solution works:

  • We take an input such as "abc"
  • Find all the permutations of the tail of the input i.e. ["bc", "cb"]
  • For each permutation, interleave the head ("a") amongst each possible position: [["abc", "bac", "bca"], ["acb", "cab", "cba"]]
  • Finally join the list of lists together by folding over it with ++ to return ["abc", "bac", "bca", "acb", "cab", "cba"]
  • The interleave function takes three arguments, for example: [] 'a' "bc"
  • It joins the three arguments together "abc"
  • It recursively calls itself but with an element taken from the right list and appended to the left: "b" 'a' "c"
  • Eventually interleave [] 'a' "bc" returns ["abc", "bac", "bca"] which is used as above.

Now I'm struggling to understand how the official implementation works. Why does their interleave function take a function as an argument? Why the need for two wheres, two lets and two inline function definitions? Are there any performance differences in the two different implementations?

submitted by aspz
[link] [3 comments]
Categories: Incoming News