News aggregator

Building static libraries with -fPIC

haskell-cafe - Wed, 06/18/2014 - 1:01pm
Hello all, I'm trying to build a shared (.so) library written in Haskell with "foreign export"s, which is statically linked with all needed dependencies. To do this, as far as I understood, I need to build all my dependencies (I use Cabal) with -fPIC flag, and also somehow get RTS static library built with -fPIC. Two questions regarding to this: 1) How can I add a build flag which will be added while building all my dependencies in Cabal. 2) How can I get needed RTS library. 3) How can I deal with "base"? Can I just build it with Cabal, so this question reduces to (1)? Thanks, Nikolay.
Categories: Offsite Discussion

Newbie question, how can one write a program that is extensible?

Haskell on Reddit - Wed, 06/18/2014 - 12:29pm

Hi, im a third year CS student, i've discovered Haskell about 2weeks ago so its very fresh to me (even if i did a little bit of OCaml last year).

I want to write a little program to try Haskell by doing, and i had in mind a kind of text editor. And i also did wonder how i could make that text editor addon friendly (because why not? that's something i wanted to try eventually but never had the chance to do until now) but couldnt find any document understandable that could help me..

Could someone tell me how i could do that? (cause i guess it is feasible? If not, why?)

Thank you very much.

(Please forgive my english, i'm not a native speaker)

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

How does "deriving Eq" work?

Haskell on Reddit - Wed, 06/18/2014 - 10:20am

I had assumed that "deriving Eq" for a parameterized data type, like "Maybe a", roughly corresponds to having a function that receives an Eq instance for "a" and returns an instance for "Maybe a". In other words, I thought that type class dictionaries can be recast as a bunch of implicit values (for non-parameterized types) and implicit conversions of these values (for parameterized types), similar to Scala implicits.

But it seems like that simple-minded picture is wrong, because the following code compiles without errors:

data Pair a b = MakePair a b deriving Eq data EvenList a = EvenNil | EvenCons (Pair a (OddList a)) deriving Eq data OddList a = OddCons (Pair a (EvenList a)) deriving Eq

The weird thing here is that constructing an Eq instance for "Pair a b" requires you to already have instances for "a" and "b", but these instances are not yet available for cases like "Pair a (OddList a)" and such. It looks like "deriving Eq" is doing something like logic programming instead, but I don't completely understand what. Is there any simple explanation of how it works?

submitted by want_to_want
[link] [15 comments]
Categories: Incoming News

ANN: haddock-library 1.0.0

General haskell list - Wed, 06/18/2014 - 8:43am
Hi, haddock-library is a package aiming to provide bits of Haddock to the rest of the Haskell world without imposing the GHC dependency that we have on the ‘haddock’ package itself. Please note that this does not deprecate the ‘haddock’ package which aims to expose other bits of Haddock, including those talking with GHC. Specifically, 1.0.0 exposes the types used by the comment parser and the parser itself. This allows you to supply the Haddock parser with String and get a Haddock ADT back out to play with. This means that if in the past you were processing Haddock strings with your own solution (or copy + pasted Alex parser we had) then you should now switch to this package instead. The API is subject to change so upper version bound is advised. Tested on 7.6.3, 7.8.x and current HEAD. The parser exposed is what is used in Haddock itself which now internally depends on this package. There are plans to move more parts into this package, exposing as much useful functionality as possible without t
Categories: Incoming News

Use -Werror by default on travis-ci

libraries list - Wed, 06/18/2014 - 5:45am
Hi, I created a PR to use -Werror by default on travis-ci. If you think this is a good idea, see any issue or have any other input, get involved in the discussion on GitHub [1]. Cheers, Simon [1] https://github.com/travis-ci/travis-build/pull/250
Categories: Offsite Discussion

return with mutable object

haskell-cafe - Wed, 06/18/2014 - 1:50am
Hi List, Per my understanding, return x would make a new copy of the object. What if the returned object is mutable? Will this make a new (mutable) object? My concern is if I created a very large mutable object, does return mutable make a full copy of the original mutable data, or just copy a reference (pointer?)? Thanks baojun _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion

How can I improve performance on defining instance Ord?

Haskell on Reddit - Wed, 06/18/2014 - 12:43am

Hi, I'm a haskell noob and reading "Beginning Haskell". I stumbled when I tried that of Exercise 4.3 which is training to get used to Set and Map using Client data type defined as follow:

data Client i = GoOrg { clientId :: i , clientName :: String} | Company { clientId :: i , clientName :: String , companyId :: Integer , person :: Person , duty :: String } | Individual { clientId :: i , person :: Person , responsible :: Bool} deriving(Show,Read,Eq)

and I defined an instance for that as below:

instance (Eq i, Ord i) => Ord (Client i) where (<) = (<) `on` (clientId)

-- (Company 1 "A" 1 (Person "XXX" "YYY" Female) "") < (GoOrg 2 "B") => True

-- (Company 3 "A" 1 (Person "XXX" "YYY" Female) "") < (GoOrg 2 "B") => False

But it didn't work and was said "out of memory" that Set.fromList [(Company 1 "A" 1 (Person "XXX" "YYY" Female) ""),(GoOrg 2 "B"),(Company 3 "C" 2 (Person "XX" "YY" Male) "")], although it worked with deriving (Ord) instead of defining instance or using fromDistinctAscList instead of fromList.

I have also checked with foldr min (maxval) [(Company 1 "A" 1 (Person "XXX" "YYY" Female) ""),(GoOrg 2 "B"),(Company 3 "C" 2 (Person "XX" "YY" Male) "")] and that was same result as above in spite of quite short list..

how can I implement that code defining instance? Thank you!

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

Hackage "500 Internal Server Error"

haskell-cafe - Tue, 06/17/2014 - 11:51pm
Is hackage uploading broken? I'm trying to upload a new version of vector-space and am getting "500 Internal Server Error". -- Conal _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion

Hoogle usage - can't find Control.Monad.Par

Haskell on Reddit - Tue, 06/17/2014 - 11:30pm

Hoogle has me stumped. I'm looking for the name of the package that implements module Control.Monad.Par. I tried

Control.Monad.Par

+Control.Monad.Par

What's the proper syntax?

Annoyingly, google find it just fine https://www.google.com/search?q=Control.Monad.Par

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

"Spinless Tagless G-Machine" erratum?

haskell-cafe - Tue, 06/17/2014 - 9:57pm
I am reading SPJ's seminal work "Implementing lazy functional languages on stock hardware: the Spinless Tagless G-machine" (1992) and I am confused by something which may be a minor notational error, or may be a key detail I am misunderstanding. The paper is available here http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.53.3729 On page 26 we have aList = {} \n Cons {thing,nil} nil = {} \n Nil {} but I have not seen this use of the notation elsewhere in the paper. It strikes me that this should be aList = {} \n {} -> Cons {thing,nil} nil = {} \n {} -> Nil {} Is my intuition correct, or am I missing a key detail? Thanks, Tom
Categories: Offsite Discussion

Why do haskellers prefer nondescriptive variables?

Haskell on Reddit - Tue, 06/17/2014 - 7:07pm

I'm working my way through the Haskell School of Music and no matter where I turn (blogs, LYAH, RWH...) Everyone uses short, nondescriptive variables. This really makes it difficult to understand certain concepts. Communities like ruby and python are very verbose, and in retrospect I think that's why those languages were easier to grasp.

Consider how much easier it is to understand (albeit a trivial example)

head :: [list] -> first_item

Than

head :: [a] -> a

If code examples were more verbose in the way their type definitions were laid out, I know for me personally that would help a great deal in deciphering more advance concepts. So why exactly do all of these tutorials use such cryptic variables? It reminds me of my school days dealing with unreadable academic C++ code.

submitted by acconrad
[link] [53 comments]
Categories: Incoming News

Alp Mestanogullari: Testing attoparsec parsers with hspec

Planet Haskell - Tue, 06/17/2014 - 6:00pm
Table of contents

Almost all haskellers end up, some day, having to write a parser. But then, that’s not really a problem because writing parsers in Haskell isn’t really annoying, like it tends to be elsewhere. Of special interest to us is attoparsec, a very fast parser combinator library. It lets you combine small, simple parsers to express how data should be extracted from that specific format you’re working with.

<section class="level1" id="getting-our-feet-wet-with-attoparsec"> Getting our feet wet with attoparsec

For example, suppose you want to parse something of the form |<any char>| where <any char> can be… well, any character. We obviously only care about that precise character sitting there – once the input is processed, we don’t really care about these | anymore. This is a no-brainer with attoparsec.

module Parser import Data.Attoparsec.Text weirdParser :: Parser Char weirdParser = do -- attoparsec's Parser type has a useful monad instance char '|' -- matches just '|', fails on any other char c <- anyChar -- matches any character and returns it char '|' -- matches just '|', like on the first line return c -- return the inner character we parsed

Here we go, we have our parser. If you’re a bit lost with these combinators, feel free to switch back and forth between this article and the documentation of Data.Attoparsec.Text.

This parser will fail if any of the 3 smaller parsers I’m using fail. If there’s more input than just what we’re interested in, the additional content will be left unconsumed.

Let’s now see our parser in action, by loading it in ghci and trying to feed it various inputs.

First, we want to be able to type in Text values directly without using conversions functions from/to Strings. For that reason, we enable the OverloadedStrings extension. We also import Data.Attoparsec.Text because in addition to containing char and anyChar it also contains the functions that let us run a parser on some input (make sure attoparsec is installed).

λ> :set -XOverloadedStrings λ> import Data.Attoparsec.Text

Data.Attoparsec.Text contains a parse function, which takes a parser and some input, and yields a Result. A Result will just let us know whether the parser failed, with some diagnostic information, or if it was on its way to successfully parsing a value but didn’t get enough input (imagine we just feed "|x" to our parser: it won’t fail, because it looks almost exactly like what we want to parse, except that it doesn’t have that terminal '|', so attoparsec will just tell us it needs more input to complete – or fail), or, finally, if everything went smoothly and it actually hands back to us a successfully parser Char in our case, along with some possibly unconsumed input.

Why do we care about this? Because when we’ll test our parsers with hspec-attoparsec, we’ll be able to test the kind of Result our parsers leaves us with, among other things.

Back to concrete things, let’s run our parser on a valid input.

λ> parse weirdParser "|x|" Done "" 'x'

That means it successfully parsed our inner 'x' between two '|'s. What if we have more input than necessary for the parser?

λ> parse weirdParser "|x|hello world" Done "hello world" 'x'

Interesting! It successfully parsed our 'x' and also tells us "hello world" was left unconsumed, because the parser didn’t need to go that far in the input string to extract the information we want.

But, if the input looks right but lets the parser halfway through completing, what happens?

λ> parse weirdParser "|x" Partial _

Here, the input is missing the final | that would make the parser succeed. So we’re told that the parser has partially succeeded, meaning that with that input, it’s been running successfully but hasn’t yet parsed everything it’s supposed to. What that Partial holds isn’t an just underscore but a function to resume the parsing with some more input (a continuation). The Show instance for parsers just writes a _ in place of functions.

Ok, and now, how about we feed some “wrong data” to our parser?

λ> parse weirdParser "bbq" Fail "bbq" ["'|'"] "Failed reading: satisfy"

Alright! Equipped with this minimal knowledge of attoparsec, we’ll now see how we can test our parser.

</section> <section class="level1" id="introducing-hspec-attoparsec"> Introducing hspec-attoparsec

Well, I happen to be working on an HTML parsing library based on attoparsec, and I’ve been using hspec for all my testing needs these past few months – working with the author surely helped, hello Simon! – so I wanted to check whether I could come up with a minimalist API for testing attoparsec parsers.

If you don’t know how to use hspec, I warmly recommend visititing hspec.github.io, it is well documented.

So let’s first get the boilerplate out of our way.

{-# LANGUAGE OverloadedStrings #-} module ParserSpec where -- we import Text, this will be our input type import Data.Text (Text) -- we import hspec, to run the test suite import Test.Hspec -- we import 'hspec-attoparsec' import Test.Hspec.Attoparsec -- we import the module where our parser is defined import Parser main :: IO () main = hspec spec spec :: Spec spec = return () -- this is temporary, we'll write our tests here

And sure enough, we can already get this running in ghci (ignore the warnings, they are just saying that we’re not yet using our parser or hspec-attoparsec), although it’s quite useless:

λ> :l example/Parser.hs example/ParserSpec.hs [1 of 2] Compiling Parser ( example/Parser.hs, interpreted ) [2 of 2] Compiling ParserSpec ( example/ParserSpec.hs, interpreted ) example/ParserSpec.hs:8:1: Warning: The import of ‘Test.Hspec.Attoparsec’ is redundant except perhaps to import instances from ‘Test.Hspec.Attoparsec’ To import instances alone, use: import Test.Hspec.Attoparsec() example/ParserSpec.hs:10:1: Warning: The import of ‘Parser’ is redundant except perhaps to import instances from ‘Parser’ To import instances alone, use: import Parser() Ok, modules loaded: Parser, ParserSpec. λ> ParserSpec.main Finished in 0.0001 seconds 0 examples, 0 failures

Alright, let’s first introduce a couple of tests where our parser should succeed.

spec :: Spec spec = do describe "weird parser - success cases" $ do it "successfully parses |a| into 'a'" $ ("|a|" :: Text) ~> weirdParser `shouldParse` 'a' it "successfully parses |3| into '3'" $ ("|3|" :: Text) ~> weirdParser `shouldParse` '3' it "successfully parses ||| into '|'" $ ("|||" :: Text) ~> weirdParser `shouldParse` '|'

We’re using two things from hspec-attoparsec:

  • (~>), which connects some input to a parser and extracts either an error string or an actual value, depending on how the parsing went.
  • shouldParse, which takes the result of (~>) and compares it to what you expect the value to be. If the parsing fails, the test won’t pass, obviously, and hspec-attoparsec will report that the parsing failed. If the parsing succeeds, the parsed value is compared to the expected one and a proper error message is reported with both values printed out.
(~>) :: Source parser string string' result => string -- ^ the input -> parser string' a -- ^ the parser to run -> Either String a -- ^ either an error or a parsed value shouldParse :: (Eq a, Show a) => Either String a -- ^ result of a call to ~> -> a -- ^ expected value -> Expectation -- ^ resulting hspec "expectation"

Running them gives:

λ> ParserSpec.main weird parser - success cases - successfully parses |a| into 'a' - successfully parses |3| into '3' - successfully parses ||| into '|' Finished in 0.0306 seconds 3 examples, 0 failures

If we modify our first test case by expecting 'b' instead of 'a', while still having "|a|" as input, we get:

λ> ParserSpec.main weird parser - success cases - successfully parses |a| into 'b' FAILED [1] - successfully parses |3| into '3' - successfully parses ||| into '|' - successfully parses a digit character from |3| 1) weird parser - success cases successfully parses |a| into 'b' expected: 'b' but got: 'a' Randomized with seed 1330009810 Finished in 0.0267 seconds 4 examples, 1 failure *** Exception: ExitFailure 1

Nice! But what else can we test? Well, we can test that what we parse satisfies some predicate, for example. Let’s add the following to spec:

-- you have to add: import Data.Char (isDigit) -- in the import list it "successfully parses a digit character from |3|" $ ("|3|" :: Text) ~> weirdParser `parseSatisfies` isDigit

where

parseSatisfies :: Show a => Either String a -- ^ result of ~> -> (a -> Bool) -- ^ predicate the parsed value should satisfy -> Expectation -- ^ resulting hspec expectation

And we get:

λ> ParserSpec.main weird parser - success cases - successfully parses |a| into 'a' - successfully parses |3| into '3' - successfully parses ||| into '|' - successfully parses a digit character from |3| Finished in 0.0012 seconds 4 examples, 0 failures

Great, what else can we do? Well, sometimes we don’t really care about the concrete values produced, we just want to test that the parser succeeds or fails on some precise inputs we have, because that’s how it’s supposed to behave and we want to have a way that changes in the future won’t affect the parser’s behavior on these inputs. This is what shouldFailOn and shouldSucceedOn are for. Let’s add a couple more tests:

spec :: Spec spec = do describe "weird parser - success cases" $ do it "successfully parses |a| into 'a'" $ ("|a|" :: Text) ~> weirdParser `shouldParse` 'a' it "successfully parses |3| into '3'" $ ("|3|" :: Text) ~> weirdParser `shouldParse` '3' it "successfully parses ||| into '|'" $ ("|||" :: Text) ~> weirdParser `shouldParse` '|' it "successfully parses a digit character from |3|" $ ("|3|" :: Text) ~> weirdParser `parseSatisfies` isDigit -- NEW it "successfully parses |\160|" $ weirdParser `shouldSucceedOn` ("|\160|" :: Text) -- NEW describe "weird parser - failing cases" $ do it "fails to parse |x-" $ weirdParser `shouldFailOn` ("|x-" :: Text) it "fails to parse ||/" $ weirdParser `shouldFailOn` ("||/" :: Text)

where

shouldSucceedOn :: (Source p s s' r, Show a) => p s' a -- ^ parser to run -> s -- ^ input string -> Expectation shouldFailOn :: (Source p s s' r, Show a) => p s' a -- ^ parser to run -> s -- ^ input string -> Expectation

And we run our new tests:

λ> :l example/Parser.hs example/ParserSpec.hs [1 of 2] Compiling Parser ( example/Parser.hs, interpreted ) [2 of 2] Compiling ParserSpec ( example/ParserSpec.hs, interpreted ) Ok, modules loaded: Parser, ParserSpec. λ> ParserSpec.main weird parser - success cases - successfully parses |a| into 'a' - successfully parses |3| into '3' - successfully parses ||| into '|' - successfully parses a digit character from |3| - successfully parses | | weird parser - failing cases - fails to parse |x- - fails to parse ||/ Finished in 0.0015 seconds 7 examples, 0 failures

I think by now you probably understand how to use the library, so I’ll just show the last useful function: leavesUnconsumed. This one will just let you inspect the unconsumed part of the input if there’s any. Using it, you can easily describe how eager in consuming the input your parsers should be.

describe "weird parser - leftovers" $ it "leaves \"fooo\" unconsumed in |a|fooo" $ ("|a|fooo" :: Text) ~?> weirdParser `leavesUnconsumed` "fooo"

Right now, hspec-attoparsec will only consider leftovers when the parser succeeds. I’m not really sure whether we should return Fail’s unconsumed input or not.

</section> <section class="level1" id="documentation"> Documentation

The code lives at github.com/alpmestan/hspec-attoparsec, the package is on hackage here where you can also view the documentation. A good source of examples is the package’s own test suite, that you can view in the repo. The example used in this article also lives in the repo, see example/. Let me know through github or by email about any question, feedback, PR, etc.

</section> Posted on June 18, 2014
Categories: Offsite Blogs

Package Maintenance: hfuse

haskell-cafe - Tue, 06/17/2014 - 5:39pm
I would like to take over maintenance of the following package: "hfuse." I have attempted to e-mail the original package author and maintainer with no response. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion

Philip Wadler: Mairi McFadyen's Open Letter to J. K. Rowling

Planet Haskell - Tue, 06/17/2014 - 3:48pm

Mairi McFadyen wrote a heartfelt response to J. K. Rowling, at National Collective.
To be asked, ‘what kind of country do you want to live in?’ is the most wonderful gift. Many people have taken this opportunity to empower themselves with knowledge. They are actively engaged in the world, not passively accepting of the status quo. They could have chosen to remain, in your own words, ‘comfortably within the bounds of their own experience, never troubling to wonder how things might be improved.’ They could remain switched off. Now we frequently overhear the #indyref discussed passionately at the taxi rank at 3 o’clock in the morning on a Friday night; in the chippy queue; at the hairdressers. It is being discussed by high school leavers: full of hope, full of promise for life and all the joy and wonders and pain it brings. ... I do not believe that independence will be easy or will somehow magically cure society’s problems. What this historical moment provides us with is an unmatched opportunity to participate in the writing of our own future. We have a chance to liberate ourselves from the stranglehold of austere Westminster politics and lead by example. We must ask ourselves, what really matters? ...We need a new story to live by. In your own words: “We do not need magic to change the world, we carry all the power we need inside ourselves already: we have the power to imagine better.”
Categories: Offsite Blogs

Philip Wadler: Scottish independence: Prof Patrick Dunleavy says Treasury claims 'ludicrous'

Planet Haskell - Tue, 06/17/2014 - 2:35pm
You couldn't make it up. The Treasury announces the cost of setting up an independent Scotland will be £2.7 billion, citing a study by Prof Patrick Dunleavy of the LSE. Dunleavy denounces the claim at 'ludicrous' and estimates the cost at £150—200 million. The Treasury then issues a new figure of £1.5 billion, citing work of Prof Robert Young of Western University in Canada. Young remarks the government has cherry-picked the largest figure, with other estimates in the paper at one half or one third as much, going on to say "It is worth pointing out that there is a lot of politics in most of these estimates and the way they are deployed. ... these costs are just money — there are other possible costs and benefits from independence that may be less easily measured ... like a secure position in the European Union or the capacity to redistribute being able to achieve higher growth rates." Full story on the BBC.
Categories: Offsite Blogs

Philip Wadler: The the impotence of proofreading

Planet Haskell - Tue, 06/17/2014 - 2:13pm
<object class="BLOGGER-youtube-video" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" data-thumbnail-src="https://ytimg.googleusercontent.com/vi/OonDPGwAyfQ/0.jpg" height="266" width="320"><param name="movie" value="https://youtube.googleapis.com/v/OonDPGwAyfQ&amp;source=uds"/><param name="bgcolor" value="#FFFFFF"/><param name="allowFullScreen" value="true"/><embed allowfullscreen="true" height="266" src="https://youtube.googleapis.com/v/OonDPGwAyfQ&amp;source=uds" type="application/x-shockwave-flash" width="320"></embed></object>My daughter introduced me to slam poet Taylor Mali.
<object class="BLOGGER-youtube-video" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" data-thumbnail-src="https://ytimg.googleusercontent.com/vi/dp9Hb8LAgqs/0.jpg" height="266" width="320"><param name="movie" value="https://youtube.googleapis.com/v/dp9Hb8LAgqs&amp;source=uds"/><param name="bgcolor" value="#FFFFFF"/><param name="allowFullScreen" value="true"/><embed allowfullscreen="true" height="266" src="https://youtube.googleapis.com/v/dp9Hb8LAgqs&amp;source=uds" type="application/x-shockwave-flash" width="320"></embed></object>
Categories: Offsite Blogs