News aggregator

The semiring of Scott reals (Thoughts aboutredesigning "Num" type class)

haskell-cafe - Sun, 09/13/2015 - 8:51pm
This departs somewhat from the thread's topic. Below I detail a semiring R that is not a ring because negation is not definable in Haskell. I further sketch integration in Haskell which I ripped off papers by Gordon Plotkin, Steve Vickers, Anders Kock and others. Infinity comes in as a limit, of course. Approximate a real number by an ascending stream of rational numbers. (The ascending can not be enforced by Haskell's type system, of course.). What you have is a so-called lower real or Scott real. Still addition and multiplication is continuous on such reals and there is a unique way of extending these operations to infinity, represented by any strictly ascending stream. Neither subtraction not division are computable for the Scott reals. Indeed, to know a lower bound of x-y one needs to know upper bounds of y. Denote this type by R: type R = Stream Rational Further consider ascending streams of Booleans, where any two streams containing True are considered semantically equivalent. type S = Stream Bo
Categories: Offsite Discussion

Dimitri Sabadie: Thoughts about software meta-design

Planet Haskell - Sun, 09/13/2015 - 2:41pm

I’ve been thinking of writing such an article for a while. A few weeks ago, I got contacted by people who wanted to know more about my experience with luminance so that they can have more hindsight about their own APIs and products.

I came to the realization that I could write a blog entry to discuss designs decisions and, at some extent, what a good design entails. Keep in mind it’s only personal thoughts and that I won’t talk for someone else.


I love mathematics because they’re elegant. Elegancy implies several traits, among simplicity, flexibility and transparency. They solve problems with very nice abstractions. In mathematics, we have a concept that is – astonishingly – not very spread and barely known outside of math geeks circles: free objects.

The concept of free is a bit overwhelming at first, because people are used to put labels and examples on everything. For instance, if I say that an object is free, you might already have associated some kind of lock to that object, so that you can get why it’s free. But we’re mistaken. We don’t need locks to define what free implies. In mathematic, a free object is an object that can’t be defined in terms of others. It’s a bit like a core object. It’s free because it can be there, no matter what other objects are around. It has no dependency, it doesn’t require no other interaction. You can also say that such an object is free of extra features that wouldn’t be linked to its nature.

This free property is a very interesting property in mathematics, because it’s surprisingly simple! We can leverage that mathematic abstraction to software design. I like keeping my softwares as much free as possible. That is – with a more human language to say it – constraining them to keep low responsibilities about what they’re doing.

Responsibility domains

The important thing to keep in mind is that you should, at first, define what the responsibility domain is all about. Let’s say you’d like to create a library to implement audio effects, like the Doppler effect – that effect actually exists for any kind of wave, but it’s interesting to synthetize it for a sound-related application. If you end up writing functions or routines to play sound or to load audio samples, you’re already doing it wrong! You’d have violated your reponsibility domain, which is, “audio effects”. Unfortunately, a lot of libraries do that. Adding extra stuff – and sometimes, worse; relying on them!

A lot of people tend to disagree with that – or they just ignore / don’t know. There’re plenty of examples of libraries and softwares that can do everything and nothing. For instance, take Qt – pronounce cute or cutie. At first, Qt is a library and an API to build up GUIs – Graphical User Interfaces – and handle windows, events and so on. Let’s have a look at the documentation of modules, here.

You can see how the responsibility domain is huge! GUI, radio, audio, video, camera, network, database, printing, concurrency and multithreading… Qt isn’t a library anymore; it’s a whole new language!

People tend to like that. “Yeah, I just have to use Qt, and I can do everything!”. Well, that’s a point. But you can also think it another way. Qt is a very massive “library” you’ll spend hours reading the documentation and will use a lot of different classes / functions from different aspects. That doesn’t compose at all. What happens when you want to – or when you don’t have the choice? – use something else? For instance, if you want to use a smaller–but–dedicated threading library? What happens if you want to use a database service you wrote or that you know it’s great? Do you wipeout your Qt use? Do you… try to make both work in harmony? If so, do you have to write a lot of boilerplate code? Do you forget about those technologies and fallback on Qt? Do the concepts map to each others?

The problem with massive libraries is the tight bound it creates between the libraries and the developers. It’s very hard with such libraries to say that you can use it whenever you want because you perfectly know them. You could even just need a few things from it; like, the SQL part. You’ll then have to install a lot of code you’ll perhaps use 10% of.


I love how the free objects from mathematics can be leveraged to build simpler libraries here. The good part about free objects is the fact that they don’t have any extra features embedded. That’s very cool, because thanks to that, you can reason in terms of such objects as-is. For instance, OpenAL is a very free audio library. Its responsibility domain is to be able to play sound and apply simple effects on them – raw and primary effects. You won’t find anything to load music from files nor samples. And that’s very nice, because the API is small, simple and straight-forward.

Those adjectives are the base of the KISS principle. The ideas behind KISS are simple: keep it simple and stupid. Keep it simple, because the simpler the better. A too complex architecture is bloated and ends up unmaintainable. Simplicity implies elegancy and then, flexibility and composability.

That’s why I think a good architecture is a small – in terms of responsibility – and simple one. If you need complexity, that’s because your responsibility domain is already a bit more complex than the common ones. And even though the design is complex for someone outside of the domain, for the domain itself, it should stay simple and as most straight-forward as possible.


I think a good API design is to pick a domain, and stick to it. Whatever extra features you won’t provide, you’ll be able to create other libraries to add those features. Because those features will also be free, they will be useful in other projects that you don’t even have any idea they exist! That’s a very cool aspect of free objects!

There’s also a case in which you have to make sacrifices – and crucial choices. For instance, event-driven programming can be implemented via several techniques. A popular one in the functional programming world nowadays is FRP. Such a library is an architectural codebase. If you end up adding FRP-related code lines in your networking-oriented library, you might be doing it wrong. Because, eh, what if I just want to use imperative event-driven idioms, like observers? You shouldn’t integrate such architectural design choices in specific libraries. Keep them free, so that everyone can quickly learn them, and enjoy them!

I like to see good-designed libraries as a set of very powerful, tiny tools I can compose and move around freely. If a tool gets broken or if it has wrong performances, I can switch to a new one or write my very own. Achieving such a flexibility without following the KISS principle is harder or may be impossible to reach.

So, in my opinion, we should keep things simple and stupid. They’re simpler to reason about, they compose and scale greatly and they of course are easier to maintain. Compose them with architectural or whatever designs in the actual final executable project. Don’t make premature important choices!

Categories: Offsite Blogs

Deriving vs instance ___ ___

Haskell on Reddit - Sun, 09/13/2015 - 12:47pm

Is there a difference between a (1) deriving clause, and (2) an instance declaration without a 'where' body?

Example (straight out of Servant tutorial 2):

data Email = Email { from :: String , to :: String , subject :: String , body :: String } deriving Generic instance ToJSON Email

How would the program change if I instead wrote: deriving (Generic,ToJSON).


I was on the inter-city bus when I wrote this post and I didn't have access to a Haskell compiler. I had a suspicion that deriving ToJSON might not compile without some extension (thanks to those who pointed out which one). I understand that deriving and instance are syntactically two different constructs.

However, my real question is: how are they different in meaning? How is a default instance different from a derived instance?

submitted by haskellStudent
[link] [13 comments]
Categories: Incoming News

the library of beautiful instruments implemented inhaskell / csound

haskell-cafe - Sun, 09/13/2015 - 10:13am
Status update for my haskell synth csound-expression. The main point is presence of many cool instruments. They are implemented in the package csound-catalog. All packages are compiled with GHC-7.10 So the hackage fails to build them and unfortunately docs a broken too. But you can look at the source code of the module Csound.Patch to now the names of the instruments. The usage is pretty straightforward. It's described here: There is an mp3 file to listen to the instruments. *The 4.8.3 is out! New features:* This is a very important release to me. It tries to solve the problem present in the most open source music-production libraries. It's often the pack of beautiful sounds/timbres is missing. User is presented with many audio primitives but no timbres are present to show the real power of the framework. This release solves this problem. See the friend package csound-catalog on Hackage. I
Categories: Offsite Discussion

Script to download the latest Stack

Haskell on Reddit - Sun, 09/13/2015 - 8:51am

Saves me a bit of time. Might save some for you too. Python.

import functools import json import re import tarfile import urllib URL = "" def compose(*funcs): return lambda x: functools.reduce(lambda v, f: f(v), funcs, x) extract_stack_content = compose( lambda t: urllib.urlopen(t), lambda t: json.load(t)["assets"], lambda t: map(lambda x: x["browser_download_url"], t), lambda t: filter(lambda x: re.match(u"^.*osx.tar.gz$", x) != None, t)[0], lambda t: urllib.urlopen(t), lambda t: = t, mode="r|gz").extractall() ) extract_stack_content(URL) submitted by stasiana
[link] [18 comments]
Categories: Incoming News

Function definition in ghci

Haskell on Reddit - Sun, 09/13/2015 - 7:40am

I want to raise a question (maybe again) about function defenition in ghci. When I write "add a b = a + b" I get "parse error on input ‘=’".

A lot of newcommers ran into this problem. When someone wants to try haskell and goes to, copies example (function primes) and pastes it into the console that is right next to example, he gets the error. This leads to a bad first impression about the language.

This page says that I should add "let" before definition because statement is evaluation as it is inside monad. But it doesn't say why it is evaluated in that way. I think that if a tool doesn't work as expected then we should improve this tool but not expectation. Moreover, ghci evaluates some expressions that are not allowed inside monad (as I know) for instance: "data Foo = Foo" and "import SomeModule".

I've made some changes in ghci to evaluate a statement that looks like function declaration outside monad but then found a test T9915 that requires to raise an error.

So, my proposal is to allow users to define function in ghci without "let". This leads to considering the current behaviour as a bug.

In future I think it should be possible to copy content of any file that ghc can compile and parse it into ghci and it will be parsed and evaluated correctly.

submitted by roshats
[link] [29 comments]
Categories: Incoming News

How to deal with duplicate record fields

Haskell on Reddit - Sun, 09/13/2015 - 2:57am

Im modeling data for my library now

It will come in JSON format and I am relying on DeriveGeneric extension to get my ToJSON / FromJSON Instances. However, there quite a lot of field duplicates in my records.

As far as I understood, I need something like DuplicateRecordFields extension

Is there any way around ?

thanks in advance

submitted by raw909
[link] [12 comments]
Categories: Incoming News

Update: I got spacemacs working, using stack, with autocomplete and everything.

Haskell on Reddit - Sun, 09/13/2015 - 12:05am

This is my .spacemacs.

I basically did stack install stylish-haskell hasktags hlint structured-haskell-mode, and installed ghci-ng and ghc-mod from source. That is all.

I hope this helps. I've been messing with Emacs to get this up for a long time.

Edit: ghci-ng is up as well, praise be to /u/cies010! Now to quit fiddling with Emacs and get some real work done. :)

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

Hostility to well defined concepts in other language communities

Haskell on Reddit - Sat, 09/12/2015 - 10:08pm

This is a genuine issue that I just dealt with: I asked in a Ruby forum about a core language feature, and I got abuse. It was weird as hell. But I've seen this kind of thing before, and I think the common denominator is that my questions inquired about the definition of a thing; it's signature and it's defined behavior. And now, when I think of it, Ruby is the non plus ultra in languages without written specification.

At any rate, the whole thing makes me appreciate Haskell and the community, all the more.

EDIT: The transcript

The person replying to me is a prominent ruby developer:

reading comprehension not your thing?


what do you really want to know?


welp... I'm done trying to pull teeth from this one. have fun with that.

submitted by dogweather
[link] [12 comments]
Categories: Incoming News

Anyone got spacemacs and stack playing well together?

Haskell on Reddit - Sat, 09/12/2015 - 8:09am

I just did a fresh Arch Linux install, and installed Emacs (GNU, 24.5.1) on it.

What would be the best way to install spacemacs and set everything up so that it all just works? I'd like structured-haskell-mode, autocomplete and type inspection to work.

If I must use cabal (I don't want to), what would the corresponding plan of action be in that case?

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

Graph-based Haskell

Haskell on Reddit - Sat, 09/12/2015 - 5:11am

I'm designing a graph-based FP language which compiles to Haskell.

I want to create something practical so I decided to extend Haskell instead of starting from scratch. This way, people will be able to use my language to do some real stuff.

In my opinion, any attempt to get rid of text is doomed to fail so, in my language, expressions are embedded in the graph, but the language encourages the use of short expressions.

The three main features of my language are

  1. Simplicity
  2. Regularity
  3. "Optionality"

Simplicity means that there must be few rules. Every Haskeller should be able to learn the language in 20 minutes or less. Mastering the language and get used to the new "paradigm" will require more time of course.

Regularity means no exceptions and, as a consequence, great composability thanks to the fact that the semantic of a graph element is independent of the context. For instance, at one point I realized that I could represent ADTs as graphs without adding any new rule or graph element.

Optionality means that whatever you can do with a graph elements, you can do with just text. This helps getting the best of both worlds (text and graphical). This also lowers the entry barrier a lot.

I've been working on this idea for about a week so I've just started!

What I need is a way to parse Haskell code, detect errors, etc... In the future I'll think about graph highlighting(!) and autocompletion. What's the easiest way of doing this?

Now please sit down.

I'd like to implement the graph editor in Scala (sic). In fact, this project is a way of getting some experience with Scala.

Maybe I could ask the authors of Frege (aka Haskell on the JVM)?

I'm still deciding on the platform: JVM or JS?

I'm craving suggestions!

submitted by Kiuhnm
[link] [33 comments]
Categories: Incoming News

wren gayle romano: What do we mean when we say "the Haskell community"?

Planet Haskell - Fri, 09/11/2015 - 9:34pm

One of the folks I've chatted with a bunch online and finally got to meet in-person this year was Gershom. Towards the end of the symposium, he mentioned the post I linked to last time about my pulling away from Haskell communities. But the way he phrased it really struck me. And I wanted to comment on that.

I guess the crux of it comes down to, what do we mean when we say "the Haskell community"? What I meant when writing that post over a year ago was the online community of Haskell learners/practitioners (i.e., the folks who dominate spaces like reddit). But what Gershom's comment suggested was the academic community of FP researchers who work on/with Haskell (i.e., the folks who dominate spaces like ICFP). These two communities have always been intertwined, but as Haskell gains popularity they feel more and more distinct.

FWIW, I do still feel welcome as part of the academic community. There are some things I could comment on, sure, but those have more to do (i think) the general issue of being a woman in tech than they do with Haskell per se. Of course, this only underscores the concern of my original post. The free exchange between academics and practitioners was always a big part of what I've loved about the (general) Haskell community. Were not for that exchange, the spark planted by Mark Jones would never have fanned into the flame of my current research. As that free exchange unravels, this pathway from interested novice to researcher is cut off. And that pathway is crucial for the vibrancy of the community, as well as for addressing those general issues of being a minority in tech.

Twitter Facebook Google+ Tumblr WordPress

Categories: Offsite Blogs

Permissive imports proposal

Haskell on Reddit - Fri, 09/11/2015 - 1:32pm

Did anything ever happen with I really like it, perhaps because I had the same idea somewhat later.

Plus (but the status there is clear).

submitted by alexeyr
[link] [51 comments]
Categories: Incoming News

Ideas for haskell exercises

Haskell on Reddit - Fri, 09/11/2015 - 12:30pm

Hello reddit, I am learning haskell, and I am already knowing a bit. I would like to create a list of exercises/challenges for me as well as other new haskellers, which will be good for learning the language. The ideas you come up with will be collected on a page on my blog with your names on :)

submitted by petermikkelsen
[link] [21 comments]
Categories: Incoming News

Ken T Takusagawa: [ajoyvtsr] Executable specification of MapReduce

Planet Haskell - Fri, 09/11/2015 - 11:39am

We present, for pedagogical purposes, a simple Haskell implementation of MapReduce.  MapReduce is a technology idea popularized by Google.  The polymorphic type signature specifies exactly what the input functions passed in by the user (mapFn and reduceFn) are supposed to do. Of course, a real MapReduce implementation would be parallel across multiple machines, fault tolerant, use external sort etc.

{-# LANGUAGE ScopedTypeVariables #-}
import Data.List(groupBy, sortOn);

mapReduce :: forall a key value b . Ord key => (a -> [(key,value)]) -> (key -> [(a,value)] -> b) -> [a] -> [b];
mapReduce mapFn reduceFn input = map (uncurry reduceFn) $ shuffle $ do { -- list monad
  x :: a <- input;
  y :: (key,value) <- mapFn x;
  return (x,y); -- all pairs

-- profiling reveals the majority of the computation time is spent here, not too surprising.
shuffle :: forall a key value . Ord key => [(a,(key,value))] -> [(key,[(a,value)])];
shuffle = let {
  get_a :: (a,(key,value)) -> a;
  get_a (a1,_) = a1;
  get_key :: (a,(key,value)) -> key;
  get_key (_,(k,_)) = k;
  get_value :: (a,(key,value)) -> value;
  get_value (_,(_,v)) = v;
  rearrange :: [(a,(key,value))] -> (key,[(a,value)]);
  rearrange l = (get_key $ head l, zip (map get_a l) (map get_value l));
} in map rearrange . groupBy (equating get_key) . sortOn get_key; -- point-free style

-- regular list sort 364.75 sec
-- Seq.unstableSortBy = 440.98 sec

-- cf Data.Ord.comparing
equating :: Eq b => (a -> b) -> a -> a -> Bool;
equating f x y = (f x) == (f y);

Categories: Offsite Blogs