News aggregator

Response to: Dynamic Typing > Static Typing?

Haskell on Reddit - Mon, 01/25/2016 - 3:06pm
submitted by
Categories: Incoming News

[Template Haskell]

haskell-cafe - Mon, 01/25/2016 - 12:58pm
Hi all, I'm just getting my feet wet with template haskell, and I tried to write a tmap function which maps a function over the ith component of an n-tuple (which uses a slightly different approach than the given version on the TH wiki):
Categories: Offsite Discussion

Extensible, reusable parsers?

Haskell on Reddit - Mon, 01/25/2016 - 11:28am
<!-- SC_OFF --><div class="md"><p>Has there been any research into the design of extensible, reusable parsers? For example, GHC and haskell-src-exts implement parsers for Haskell, but neither are extendable with custom syntax without having to maintain a fork of the entire implementation. The alternative is to reimplement parsing for the whole language just to add a few constructs on top.</p> <p>Another example: if you wanted to parse JSON with comments, you couldn't reuse any of, say, aeson's implementation—you'd have to write a new JSON parser from the ground up.</p> <p>One could expose the component parsing functions and combinators of a parsec-based parser as a library, but this could be fragile depending on the way the parser is structured.</p> <p>Is this something that has been or is being worked on already? Are there fundamental barriers to this problem?</p> </div><!-- SC_ON --> submitted by
Categories: Incoming News

Local types

haskell-cafe - Mon, 01/25/2016 - 10:11am
I often wish to be able to define local types and instances, so, for example: import Data.Set as Set ordNubBy :: (a -> a -> Ordering) -> [a] -> [a] ordNubBy cmp = go Set.empty where newtype T = T a instance Ord T where T x `compare` T y = cmp x y go _ [] = [] go ys (x:xs) = bool (x:) id (T x ∈ ys) $ go (Set.insert (T x) ys) xs The notion is that type and instance declarations would become legal in `let` or `where` bonds; they would effectively declare new types and instances in that scope for each use of that term; and such local types and instances could never leave the scope they were defined in, by enforcement, so consistency of instances would be preserved. I know some related work which proposes local instances [0] but none i know proposes also local types. I'm seeking some feedback here before i formalize further and potentially start making implements. Thoughts? Questions? Better ideas? Critical flaws? [0] http://okmij.org/ftp/Haskell/TypeClass.html#local __________
Categories: Offsite Discussion

trying to build Hackage hoq-0.3

haskell-cafe - Mon, 01/25/2016 - 9:22am
1) ghc version 7.6.3 2) cabal version 1.16.0.2 3) when i run "cabal install", I receive on stdout : Resolving dependencies... Configuring readline-1.0.3.0... checking for gcc... gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking for GNUreadline.framework... checking for readline... no checking for tputs in -lncurses... no checking for tputs in -ltermcap... no checking for tputs in -lcurses... no checking for rl_readline_version... no configure: error: readline not found, so this package cannot be built See `config.log' for more details. Failed to install readline-1.0.3.0 cabal: Error: some packages failed to install: hoq-0.3 depends on readline-1.0.3.0 which fai
Categories: Offsite Discussion

Local documentation

Haskell on Reddit - Mon, 01/25/2016 - 6:56am
<!-- SC_OFF --><div class="md"><p>How do you people search documentation locally? The options I know are:</p> <ul> <li>Cabal generated docs (I find it clumsy to search them)</li> <li>Local Hoogle instance (It is one of these things that are easier with a proper GUI)</li> <li>Zeal (does not contain all my installed packages)</li> </ul> <p>Is there something I missed that is more practical? I always end up going to online hoogle or to the hackage docs. Maybe something that serves a local &quot;hackage&quot; in a local url? Thanks!</p> </div><!-- SC_ON --> submitted by
Categories: Incoming News

Emulate keyboard and mouse events?

Haskell on Reddit - Mon, 01/25/2016 - 6:05am
<!-- SC_OFF --><div class="md"><p>Hi,</p> <p>Can anyone let me know how to emulate keyboard and mouse events in Haskell?</p> </div><!-- SC_ON --> submitted by
Categories: Incoming News

When to not use operator-overloading?

Haskell on Reddit - Mon, 01/25/2016 - 5:43am
<!-- SC_OFF --><div class="md"><p>I was asked a question a couple of days ago, regarding operator-overloading. I don't think that I was able to give a full answer, so I was wondering if you guys would know.</p> <p>The question is: &quot;Why do some programming languages have different operators for adding two numbers and adding (concatenating) two lists or strings? E.g. in Haskell we use <code>2+2</code> for numbers and <code>[2] ++ [2]</code>for lists.&quot;</p> <p>If you can do operator-overloading, why don't you in these cases? My answer had to do with types and the compiler not knowing the end type after the operation without actually executing it. E.g. what is the resulting type of:</p> <pre><code>c = a + b </code></pre> <p>if <code>+</code> is both adding and concatenating? One could also look at the expression:</p> <pre><code>c = &quot;H&quot; + 5 + 5 </code></pre> <p>and ask about the precedence of the execution, if you allow the compiler or interpreter to typecast your values. This example could be both <code>&quot;H55&quot;</code> or <code>&quot;H10&quot;</code> depending on which <code>+</code> was executed first. Is this the reason?</p> </div><!-- SC_ON --> submitted by
Categories: Incoming News

State of HaLVM?

Haskell on Reddit - Mon, 01/25/2016 - 5:03am
<!-- SC_OFF --><div class="md"><p>With the announcement of the acquisition of Unikernel Systems [1], it looks like there might be renewed interest and investment in this area. There are signs of movement in the HaLVM area already [2] but it isn't clear to me what the overall state of the HaLVM world currently is. Can anyone summarise for me; and maybe indicate how people interested in contributing might get involved?</p> <p>[1] <a href="http://thenewstack.io/docker-buys-unikernel-systems-plans-bring-unikernels-data-center/">http://thenewstack.io/docker-buys-unikernel-systems-plans-bring-unikernels-data-center/</a> [2] <a href="https://devel.unikernel.org/t/halvm-rump-kernel-integration/52">https://devel.unikernel.org/t/halvm-rump-kernel-integration/52</a></p> </div><!-- SC_ON --> submitted by
Categories: Incoming News

Yesod Web Framework: Auto generate Docbook XML for the Yesod book

Planet Haskell - Mon, 01/25/2016 - 4:30am

I just made a minor tweak to the yesodweb.com-content repository, which contains all of the content that gets displayed on this site, including this blog post and the entire Yesod book. This repo contains both the original asciidoc version of the content, as well as the XML docbook files that are generated from it. Though that's a slightly contentious decision, storing it this way avoids having to have the asciidoc tools installed on the server hosting the website.

Until now, I've had to manually generate the XML from time to time after making updates or merging pull requests. However, doing this kind of manual maintenance is annoying. Much better to use automated systems. And whenever possible, I like to go for Travis CI. The setup is pretty simple, but involves some finer points that I thought may be interesting to others (not to mention good documentation for myself in the future).

Encrypted deployment key

In order to push from Travis back to Github, we need to have an SSH key. Travis allows us to put encrypted content into the repo, which anyone can see themselves. Within Travis, this file can be decrypted and then placed in the ~/.ssh directory with the following commands:

mkdir -p $HOME/.ssh openssl aes-256-cbc -K $encrypted_92ac0cbbb1f3_key -iv $encrypted_92ac0cbbb1f3_iv -in id_rsa.enc -out id_rsa -d mv id_rsa $HOME/.ssh chmod 400 $HOME/.ssh/id_rsa

If you want to create your own encrypted files for Travis, you'll want to use the Travis command line interface's encrypt-file command.

Get necessary prerequisites installed

In order to build the XML files, we need three tools: asciidoc, GHC, and Stack. The first two can be installed via apt, but until travis-ci/apt-source-whitelist#7 is merged, we need to install Stack more manually. This is all still pretty easy to get set up:

addons: apt: packages: - asciidoc - ghc-7.10.3 sources: - hvr-ghc install: - export PATH=$HOME/.local/bin:/opt/ghc/7.10.3/bin:$PATH - mkdir -p $HOME/.local/bin - curl -L https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'Generate the XML

This part's easy: we wipe out the original XML files and run the generate.sh script:

- rm -f book/generated-xml/* - book/tools/generate.sh - git diff

We run git diff at the end to provide some useful feedback during PRs of the resulting XML difference.

Commit and push

This is where the magic happens. Let's look at the code (a bash script inlined in the YAML for Travis):

- | if [ $TRAVIS_PULL_REQUEST != false ] then echo Not pushing diff for a pull request elif [ -n "$(git status --porcelain)" ] then mkdir -p $HOME/.ssh openssl aes-256-cbc -K $encrypted_92ac0cbbb1f3_key -iv $encrypted_92ac0cbbb1f3_iv -in id_rsa.enc -out id_rsa -d mv id_rsa $HOME/.ssh chmod 400 $HOME/.ssh/id_rsa git config --global user.email "michael+travis@snoyman.com" git config --global user.name "Travis job for yesodweb/yesodweb.com-content" git add -A git commit -m "Travis auto-generate XML files, $(date --utc --iso=sec)" git push git@github.com:yesodweb/yesodweb.com-content.git HEAD:$TRAVIS_BRANCH else echo No changes present fi

If we're looking at a pull request, we don't want to ever push to the branch. (Travis will also prevent us from making a silly mistake here, since the decryption key we need to get the SSH key won't be available.) We also check if there are any changes to the XML files. But in the case of a non-PR build that has changes, we:

  1. Set up the SSH key, as we described above
  2. Commit all changes locally
  3. Push the changes to the current branch (1$TRAVIS_BRANCH`)
Full file

You can look at the current version of the .travis.yml on Github. Here's the content at the time of writing:

language: c sudo: false cache: directories: - $HOME/.stack addons: apt: packages: - asciidoc - ghc-7.10.3 sources: - hvr-ghc install: - export PATH=$HOME/.local/bin:/opt/ghc/7.10.3/bin:$PATH - mkdir -p $HOME/.local/bin - curl -L https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack' script: - rm -f book/generated-xml/* - book/tools/generate.sh - git diff - | if [ $TRAVIS_PULL_REQUEST != false ] then echo Not pushing diff for a pull request elif [ -n "$(git status --porcelain)" ] then mkdir -p $HOME/.ssh openssl aes-256-cbc -K $encrypted_92ac0cbbb1f3_key -iv $encrypted_92ac0cbbb1f3_iv -in id_rsa.enc -out id_rsa -d mv id_rsa $HOME/.ssh chmod 400 $HOME/.ssh/id_rsa git config --global user.email "michael+travis@snoyman.com" git config --global user.name "Travis job for yesodweb/yesodweb.com-content" git add -A git commit -m "Travis auto-generate XML files, $(date --utc --iso=sec)" git push git@github.com:yesodweb/yesodweb.com-content.git HEAD:$TRAVIS_BRANCH else echo No changes present fi

There's nothing particularly complicated or earth-shattering about this approach, but hopefully putting it all together like this can help others implement this themselves more easily.

Categories: Offsite Blogs

Integrating slack with emacs

Haskell on Reddit - Mon, 01/25/2016 - 2:49am
<!-- SC_OFF --><div class="md"><p>Hey gang!</p> <p>I haven't worked with Haskell for a while, and recently got back into it. Looking at what had changed in the landscape, I discovered <a href="https://github.com/commercialhaskell/stack">Slack</a>. Since I do all of my development in Emacs, I'm wondering what the best way (if any) to integrate Slack with Emacs?</p> </div><!-- SC_ON --> submitted by
Categories: Incoming News

Beginner learns Haskell

Haskell on Reddit - Mon, 01/25/2016 - 2:31am
<!-- SC_OFF --><div class="md"><p>So I'm learning Haskell as a total noob without any background in programming and I keep track of my progress on a blog: <a href="http://polandfinlandplayground.org/2016/01/25/me-learning-programming-solving-problems/">http://polandfinlandplayground.org/2016/01/25/me-learning-programming-solving-problems/</a></p> <p>and</p> <p><a href="http://polandfinlandplayground.org/2016/01/19/me-learning-programming-the-beginning/">http://polandfinlandplayground.org/2016/01/19/me-learning-programming-the-beginning/</a></p> </div><!-- SC_ON --> submitted by
Categories: Incoming News

IO action that results in a Function changes it's Type

Haskell on Reddit - Mon, 01/25/2016 - 1:09am
<!-- SC_OFF --><div class="md"><p>Probably best i just show you, i typed the following into ghci:</p> <blockquote> <p>&gt;let f = return (\a -&gt; show a + &quot;test&quot;) :: Show a =&gt; IO (a -&gt; String)<br/> &gt;pf &lt;- f<br/> &gt;:t pf<br/> pf :: () -&gt; String</p> </blockquote> <p>Now why isn't it &quot;Show a =&gt; a -&gt; String&quot; , why does the a get converted to Unit?</p> </div><!-- SC_ON --> submitted by
Categories: Incoming News

Type class for sanity

libraries list - Sun, 01/24/2016 - 11:24pm
Since type families can be stuck, it's sometimes useful to restrict things to sane types. At present, the most convenient way I can see to do this in general is with Typeable: type family Foo x where Foo 'True = Int class Typeable (Foo x) => Bar x where blah :: proxy x -> Foo x This will prevent anyone from producing the bogus instance instance Bar 'False where blah _ = undefined Unfortunately, the Typeable constraint carries runtime overhead. One possible way around this, I think, is with a class that does just sanity checking and nothing more: class Sane (a :: k) instance Sane Int instance Sane Char instance Sane 'False instance Sane 'True instance Sane '[] instance Sane '(:) instance Sane (->) instance Sane 'Just instance Sane 'Nothing instance (Sane f, Sane x) => Sane (f x) To really do its job properly, Sane would need to have instances for all sane types and no more. An example of an insane instance of Sane would be instance Sane (a :: MyKind) which would include stuck types of kind MyKi
Categories: Offsite Discussion

The HTML Monad: Part I

Haskell on Reddit - Sun, 01/24/2016 - 9:08pm
<!-- SC_OFF --><div class="md"><p>This is a literate Haskell Post. Simply copy and paste this whole thing into a file called &quot;pad.lhs&quot; and run it! </p> <p>&nbsp;</p> <pre><code>&gt; {-# LANGUAGE FlexibleInstances, OverloadedStrings #-} &gt; import GHC.Exts (IsString, fromString) -- Nothing magic, just for Overloaded Strings &gt; import Data.Void </code></pre> <p>&nbsp; </p> <p>What exactly is an HTML template. Well, an HTML template is an HTML document with a bunch of holes in it, waiting to be filled. In particular, given a way to fill the holes, we can produce a document. Hey, that can be made into a higher-order function! </p> <p>&nbsp;</p> <pre><code>&gt; newtype ContH a = ContH {run :: (a -&gt; String) -&gt; String} </code></pre> <p>&nbsp;</p> <p>(As you can see. I'm using <code>String</code> for HTML. This is for easy of exposition only. For an actual thing, you would want to use some sort of Tree to repersent HTML (such as used in <a href="http://hackage.haskell.org/package/tagsoup/docs/Text-HTML-TagSoup-Tree.html#t:TagTree">tagsoup</a>). See the end of the post. (Also, ignore <code>XSS</code> for now.)) Wait a minute. That's just a <a href="http://www.haskellforall.com/2012/12/the-continuation-monad.html">continuation</a>! And <a href="http://www.thev.net/PaulLiu/invert-inversion.html">continuations</a> are <a href="http://blog.sigfpe.com/2008/12/mother-of-all-monads.html">terrific</a>! (Those links should give you a feel for this monad.) Let's go ahead and define a Monad instance. (<code>ContH a</code> generally won't be showable. If you are following along at home, if you want to view a value of <code>ca :: ContH a</code>, where <code>a</code> is showable, do <code>run ca show</code>. This will just plug the string version of each <code>a</code> into the html document.) </p> <p>&nbsp;</p> <pre><code>&gt; instance Functor ContH where &gt; fmap f (ContH ca) = ContH $ \k -&gt; ca $ \a -&gt; k $ f a &gt; instance Applicative ContH where &gt; pure a = ContH $ \k -&gt; k a &gt; (ContH cab) &lt;*&gt; (ContH ca) = ContH $ \k -&gt; &gt; cab $ \ab -&gt; &gt; ca $ \a -&gt; &gt; k $ ab a &gt; (ContH ca) *&gt; (ContH cb) = ContH $ \k -&gt; &gt; ca $ const $ &gt; cb $ \b -&gt; &gt; k b &gt; instance Monad ContH where &gt; (ContH ca) &gt;&gt;= acb = ContH $ \k -&gt; &gt; ca $ \a -&gt; &gt; run (acb a) k &gt; return = pure &gt; (&gt;&gt;) = (*&gt;) </code></pre> <p>&nbsp;</p> <p>I've written it to make it hopefully understandable what's going on. <code>k</code> is the &quot;what to fill the holes with&quot; parameter. <code>ca</code> is &quot;give me a way to fill holes of type <code>a</code>, and I give you HTML&quot;.</p> <p>Now, what can we do? Well, a tag (such as the <code>&lt;a&gt;</code> tag), can be seen as an html document with one hole (what goes between the tags). One hole would mean we have type <code>()</code> (a.k.a. there is no difference between the holes). </p> <p>&nbsp;</p> <pre><code>&gt; a :: String -&gt; ContH () &gt; a link = ContH $ \k -&gt; &quot;&lt;a href=&quot; ++ show link ++ &quot;&gt;\n&quot; ++ k () ++ &quot;&lt;/a&gt;\n&quot; </code></pre> <p>&nbsp;</p> <p>We can generalize easily </p> <p>&nbsp;</p> <pre><code>&gt; tag :: String -&gt; ContH () &gt; tag t = ContH $ \k -&gt; &quot;&lt;&quot; ++ t ++ &quot;&gt;\n&quot; ++ k () ++ &quot;&lt;/&quot; ++ t ++ &quot;&gt;\n&quot; </code></pre> <p>&nbsp;</p> <p>An html list can be seen as something with a bunch of holes. Instead of picking what to label the holes, we let the programmer pick the labels. </p> <p>&nbsp;</p> <pre><code>&gt; list :: [a] -&gt; ContH a &gt; list lst = do &gt; tag &quot;ul&quot; &gt; ContH $ \k -&gt; unlines $ map (\a -&gt; &quot;&lt;li&gt;\n&quot; ++ k a ++ &quot;&lt;/li&gt;&quot;) lst </code></pre> <p>&nbsp;</p> <p>Notice that <code>tag &quot;ul&quot;</code> causes the rest of the computation to be wrapped in a <code>&lt;ul&gt;</code> tag. This is very characteristic of continuations. Also notice that we are using <code>k</code> multiple times. This means the rest of the continuation after a list xs will be run for each item of the list, sort of like a list monad. </p> <p>In general, we can take any html template and make it to a <code>ContH String</code>. For example, if we have a document of the form</p> <pre><code>&lt;html&gt;&lt;title&gt;&lt;hole id=&quot;Title&quot;&gt;&lt;/title&gt;&lt;body&gt;&lt;hole id=&quot;Date&quot;&gt;&lt;p&gt;&lt;hole id=&quot;Content&quot;&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt; </code></pre> <p>We could systematically turn that into a template of the form. (We do it manually for this simple tutorial. If we had an html parser, such as <code>tagsoup</code>, it would be easy to make a function to do it for us.)</p> <p>&nbsp;</p> <pre><code>&gt; template :: ContH String &gt; template = ContH $ \k -&gt; &quot;&lt;html&gt;&lt;title&gt;&quot; ++ k &quot;Title&quot; ++ &quot;&lt;/title&gt;&quot; ++ &quot;&lt;body&gt;&quot; ++ k &quot;Date&quot; ++ &quot;&lt;p&gt;&quot; ++ k &quot;Content&quot; ++ &quot;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;&quot; </code></pre> <p>&nbsp;</p> <p>But dealing with <code>String</code>s to label our holes is burdensome, and prone to hard to find runtime errors. Luckily, <code>ContH</code> is a functor. </p> <p>&nbsp;</p> <pre><code>&gt; data Holes = Date | Content | Title deriving (Show, Read) &gt; template' :: ContH Holes &gt; template' = fmap read template where </code></pre> <p>&nbsp;</p> <p>If we were to use <code>template'</code> in do-notation, we would bind it, and then do a case analysis of <code>Holes</code>. We can verify that <code>template'</code> is good before proceeding to use it in the rest of the program by doing something like <code>run template' show</code>, since this will throw an error is a bad hole was used. We could also use <code>readMaybe</code>. You may start to be seeing the potential now.</p> <p>Indeed, we can give <code>ContH</code> all sorts of crazy types, including functions, or even other <code>ContH</code>s (which would in turn allow us to use <code>join</code>.) But let's look at one simple, but powerful possibility. </p> <p>&nbsp;</p> <pre><code>&gt; type HTML = ContH Void </code></pre> <p>&nbsp;</p> <p>For those of you who don't know, <code>Void</code> is a type with no values (besides <code>undefined</code>). So <code>ContH Void</code> is just a html template with no holes, a.k.a. a html document! But if <code>Void</code> has no values, how do we make a <code>ContH Void</code>? Simple, we just never pass anything into <code>k</code> (since we can't) and just return the document. </p> <p>&nbsp;</p> <pre><code>&gt; instance IsString (ContH Void) where --This allows us to use overloaded strings. &gt; fromString cs = ContH $ \k -&gt; cs </code></pre> <p>&nbsp;</p> <p><code>absurd</code> takes a Void, and returns a value of type <code>a</code>, for any type <code>a</code>. How? Well since <code>Void</code> has no values, it's just an empty function. We can use this to convert HTML to an actual HTML document. </p> <p>&nbsp;</p> <pre><code>&gt; toString :: HTML -&gt; String &gt; toString h = run h absurd </code></pre> <p>&nbsp;</p> <p>We can see this as a type of contract. <code>ContH Void</code> promises to never use <code>k</code>, so <code>toString</code> doesn't have to provide a meaningful value for it. One thing we might want to do is, besides nesthing html, put pieces of html one after the other. This can be done like so. </p> <p>&nbsp;</p> <pre><code>&gt; i :: HTML -&gt; ContH () &gt; i h = ContH $ \k -&gt; toString h ++ k () </code></pre> <p>&nbsp;</p> <p>Now let's combine everything we've learned. </p> <p>&nbsp;</p> <pre><code>&gt; finalChallenge :: HTML &gt; finalChallenge = do &gt; tag &quot;html&quot; &gt; i $ tag &quot;title&quot; &gt;&gt; &quot;Google Searches&quot; &gt; tag &quot;body&quot; &gt; i &quot;My favorite google searches!&quot; &gt; i $ do &gt; thing &lt;- list [&quot;haskell&quot;, &quot;lambdas&quot;, &quot;cats&quot;] &gt; a (&quot;http://google.com?q=&quot; ++ thing) &gt; fromString $ thing &gt; &quot;What are yours?&quot; </code></pre> <p>&nbsp;</p> <p>This generates:</p> <pre><code>&lt;html&gt; &lt;title&gt; Google Searches&lt;/title&gt; &lt;body&gt; My favorite google searches!&lt;ul&gt; &lt;li&gt; &lt;a href=&quot;http://google.com?q=haskell&quot;&gt; haskell&lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href=&quot;http://google.com?q=lambdas&quot;&gt; lambdas&lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href=&quot;http://google.com?q=cats&quot;&gt; cats&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; What are yours?&lt;/body&gt; &lt;/html&gt; </code></pre> <p><a href="http://jsbin.com/loyewemaka/edit?html,output">Success!</a></p> <p>What do you all think of this. I'm thinking of making it a library (improving a lot of things, of course (definitely not going to represent HTML using String.)) In particular, is there anything where you didn't like how I did it? Continuations are very powerful, so it would probably be easy to implement your suggestions.</p> <p>Happy Hacking!</p> <p>For those who want a more fleshed out example: see <a href="http://lpaste.net/150853">http://lpaste.net/150853</a> (It is more resilient to XSS, includes template parsing and rendering, and includes attributes (the attributes thing is cool, go take a look).) It even contains a Bonus Exercise!</p> <p>(I haven't written it yet (I'll put a link here when I do), but I plan to write a sequel. It would go over different even more powerful uses (such as manipulation of attributes, and the ability to format children), as well as how to combine it with other monads for more power (including almost making your so called &quot;html templates&quot; a full web app (whilst still being eerily similar to an html template.))</p> </div><!-- SC_ON --> submitted by
Categories: Incoming News

transformers appears to benefit from more inline

haskell-cafe - Sun, 01/24/2016 - 8:21pm
Hi everyone, I've recently been playing with a little mtl-like approach to streaming data, whereby I have a single type class - MonadYield - which can yield data, and then I use various implementations of this type class to implement operations. My usual approach to this is to implement this by newtyping around appropriate "off-the-shelf" monad transformers from the transformers library, but I found that this incurs a significant performance penalty. I've tried to put some fairly extensive benchmarks in place, which you can find at https://github.com/ocharles/monad-yield. In that repository is a README.md file that describes how I have been performing these benchmarks. The benchmarks are defined over a common interface that each implementation of MonadYield exports. The benchmarks are defined in "Benchmarks.hs", and the three implementations are "Transformers.hs" (using transformers from GHC), "TransformersInline.hs" (using transformers-ocharles from that repository, which has many more INLINE pragmas) and
Categories: Offsite Discussion

Parsing Bitstreams with haskell

Haskell on Reddit - Sun, 01/24/2016 - 2:32pm
<!-- SC_OFF --><div class="md"><p>I'm very new to haskell and I am at the point where I would like to do little projects to learn more. My professional career consists of programming audio decoder / encoders in C,so I thought a good start would be parsing Bitstreams. I found the Bytestream examples in &quot;learn you a haskell&quot; but there does not seem to be support for bit fields that are smaller than 8 bits. I found a couple of packages in hackage.haskell.org, but wasn't able to identify which is the right one for this task. Any ideas?</p> </div><!-- SC_ON --> submitted by
Categories: Incoming News

Freer play with effects

Haskell on Reddit - Sun, 01/24/2016 - 11:44am
submitted by
Categories: Incoming News

Free play, part two

Haskell on Reddit - Sun, 01/24/2016 - 8:53am
submitted by
Categories: Incoming News

When are MVars better than STM?

haskell-cafe - Sun, 01/24/2016 - 8:46am
Hi friends, Using Criterion, I have been running benchmarks to measure the relative performance of STM and MVars for some simple transactions that I expect will be typical in my application. I am using GHC 7.10.2 and libraries as at Stackage LTS 3.2. I have found that STM is faster than MVars in all my benchmarks, without exception. This seems to go against accepted wisdom [1][2][3]. I have not included my source code here to save space, but if you suspect that I am using MVars incorrectly, just say so and I will post my source code separately. I have two questions: 1. When are MVars faster than STM? If the answer is "never", then when are MVars "better" than STM? (Choose your own definition of "better".) 2. When given two capabilities (+RTS -N2), MVars are suddenly an order of magnitude slower than with just one capability. Why? For those who want details: My benchmark forks four Haskell threads. Each thread repeats a transaction that increments a shared counter many, many times. These transactions
Categories: Offsite Discussion