News aggregator


Haskell on Reddit - Fri, 04/11/2014 - 9:18am

Why isn’t there a clamp function in Data.Ord? Something like that:

clamp :: (Ord a) => a -> a -> a -> a clamp mn mx = max mn . min mx

We have min and max, clamp is a very useful function as well, and very famous.

submitted by _skp
[link] [23 comments]
Categories: Incoming News

Is GHC the defacto standard?

Haskell on Reddit - Thu, 04/10/2014 - 10:12pm

I haven't looked into how the Haskell language is standardized, but I have noticed that articles and libraries seem to liberally use extensions specific to GHC, or at least that GHC lists as syntactic extensions. In comparison, the Hugs compiler looks pretty boring and no one talks about it much.

I learned to program with C++, and that community cares very much about standard conformance, but we also have multiple compilers on multiple OS's and we want to write code that conforms to everyone at once. So when referring to Haskell, should one assume that everyone conforms to GHC, even if GHC does not define Haskell? On a related note: does anyone use a compiler other than GHC, including Hugs, and why?

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

Douglas M. Auclair (geophf): 'I' is for isomorphism

Planet Haskell - Thu, 04/10/2014 - 10:07pm

'I' is for isomorphic
Howdy, howdy, howdy! ('H' is for Howdy, but howdy ends with the Y-combinator, so we'll talk about then we cover the letter 'Y,' as in 'Y' is for Recursion.)
(I laugh, but the Y-combinator isn't necessarily ... well, anything, and not even recursive, because it could be it's opposite: inductive) (and by 'opposite' you do know I mean 'dual.')
(Uh, yeah, that.)
So, this new math, this new way of counting, the new way of proving everything, the new, new way of proving you can't prove everything, like, oh, location and velocity at one point.
What's really neat is these new maths prove the coast of Britain is how long, precisely?
Trick question. You may say, 'Oh, the coast of Britain is about 2,000 miles long,' because you're forgetting that the British don't use the British Imperial system to measure distance anymore, 'cause that's how those wild brits roll.
The metric system, it's so perfectly square, it's cool! (Square, geddit?)
... for those cool brits, because I guarantee you it's below 30° outside on the 2,000 miles of Britain's coast.
It's also a trick question, because using fractal geometries ('fract': 'to break' into smaller and smaller pieces), Mandelbröt, the inventor of the geometry has measured a very precise length of the British coast:
It's infinite length. Immeasurably so. Mandelbröt knows. He measured it.
Bully for him. Question: did he actually walk those zillion + 1 metres? Huh? Did he? Huh?
All these mathematicians making these bold proclamations, like 'oh, the British coast, when more and more exactly measured, is of infinite length!'
But do they put their moneys (pounds? why is money so heavy? or euros? Why is money so cute and feminine? euro from Europa. And why is Zues always turning himself into a bull to chase the ladiez? These are imponderables that one faces, from time to time.)
(I mean like all over Greek mythology, girlz be havin' the hots for bulls and having bull-kids tha spawn really, really bad fanfiction ... you do know what Catching Fire and Mockingjay are based on, don't you? "Oh, I, Medea will be tribute for my little sister, 'cause I suddenly totally kick ass with the bow, because Battle Royale was made a decade earlier and a decade times better, but nobody knows Battle Royale nor Greek Mythology, so I'll just crib it for some tons of moneys!" Like Fifty Shades of Grey was originally really bad Twilight fanfiction, which isn't hard to find: really bad Twilight fanfiction.)
(Now Twilight came about because Connecticut kicked a girl to the curb who had really bad self-esteem issues, so she wrote a book about that ... and about sparkly vampires. And twenty-eight publishing companies told her: 'You're joking, right?' then Summit made a really bad movie about it, and all the goth girls lined up to see it, and that's when people said, 'Huh, I guess it's got something, like Harry Potter, which is a story that, as far as I can tell, about a fat uncle who wants to punch this nerdlinger who fed his owl once in seven books in the face, but he never got that pleasure.)
(The magic of Harry Potter? He has a zero-maintenance owl, and more magic? "Gryffindor wins!" Because why? Because of PFM, that's why!)
(But don't worry if you missed it the first time, because the exact same thing repeats in the next six books, but with just more and more pages, and a kitchen elf with mismatched socks and pro-labour sentiments.)
Yeah. 'I' is for isomorphic, ... that's what I was talking about. I'm sure of it.
Kinda. Sorta.
So, the question of equality comes up in this new world of not caring what your operating on, as the operators or functions are the bees' knees.
So how do you tell if two things are 'equal' and what does 'equal' mean now? I mean, saying 
5 == 5 
is simple enough in the category of numbers, but then what about of the categories of functions on numbers, how do you measure equality? Or how about where the units are categories? In the category of categories how do you know that one category is 'equal' to another category? Or, testing the identity function, for example, when an object is transformed for a function that may or may not be the identity function, how can you tell the object in the codomain is 'the same' as the object in the domain before the function was applied?
It's actually pretty simple, actually. What's hard is saying two things are equal without a clear definition of what equality is.
So let's give the categorical definition of equality: isomorphism. That's a word from the Greek, iso, meaning 'the same' and morphism, meaning 'shape.'
Equality is that object A is equivalent to object B if they both have the 'same' 'shape.'
Now, for things without a shape that your familiar with ...
For example, numbers have 'shape' in their magnitude, ...
and parallelograms have shape in their ... well, shape.
But what is the 'shape' of a function? You can't look 'inside' a function to inspect its shape, just as you don't look inside a number to see that the number 3 has the same shape of the sum of the numbers 1 and 2.
Question: what's 'inside' a number?Answer: Nothing.
Solved that problem that's been bugging mathematicians since Plato and Euclid, so, moving on.
That problem's solved, but that still leaves the question of the shape of functions, and then the shape of categories.
Well, in some cases the shape of things is undecidable, because, for example, one way to determine (if you can) the shape of functions, or to see if two functions are equivalent, is to feed the same arguments to each of the functions, then to see that if, for the same input values, both functions return the same output values (because the output values have the same shape) (again, that aggravatingly ambiguous test!) then we have equivalence.
The problem if you have something like this function:
let f x = f (x + 1)
Then what is the answer to that?
f 0 = f 1 which is f 2 which is f 3 which is f 4 ...
You'll never be able to determine the shape of that function, because for each value you give to f, it seeks the solution by monotonically increasing the argument, ad infinitum.
So what shape is f? And what if g is
let g y = f (y + 1)
does g have the same shape as f? Sure, ... right? But how do you verify that?
Or how about 
let h z = h (g (f z))
What shape is h? Is it the same shape as f or g? or neither of them?
These are valid formulations, but how can we reason about them and then across them to make statements of truth of how these functions relate to each other that we can prove? For many numbers (but not all!) (take that!), many functions, and even many categories, determining equality, or, correctly, isomorphism, is decidable: we inspect the shape (usually with a shape-defining function), see that they are the same, and say, behold, objects A and B are isomorphic! And we're done.
Which is a vast improvement to what we had before:
"I assume for every p, p == p is true.."
Which is saying something equals itself because it equals itself.
But then how do you know p == q is true if you don't know what q may be, either p or not p, or in the same shape as p. If q is the same shape as p, inhabiting it, is it 'equal' to p?
In Category Theory, we say, 'yes.'
Why do we say 'yes' so easily? 
Because we don't care what p and q are. 
We care what the functions do. And a function taking either p or q as argument returning the same value, every time.
Good enough (verifiably so) for me. Our functions behave consistently. Let's move on.
To 'j'.
Oh, in Latin, there is no 'j.' Not that I'm being IVDGMENTAL or anything.
Here's a neat, little number. Tiny. Infinitesimal, in fact.
The number: *.
That's right. * ('star') is a number. In Game Theory it is the number denoting that in a two-player game, the person who has the next move has only a bad move to make.
The neat thing about * is this. No other number is equal to it. In fact * is the only number there this statement is true:
* =/= *
Star is not even equal to itself.
So where
1 = 1
is a provable (and proved) statement of truth, this infinitesimal has it's own statement of truth:
* || *
This reads: "star is incomparable to star."
Okay, so, now you have a conversation-starter at all the cocktail parties and soirées that you're attending, you stunning socialite, you.
Don't say I never gave you anything. Have a star.
geophf to move and win.
After all, I did give you the *-move.
So: 'I' for isomorphic ... or is it for the incomparable infinitesimal that isn't?
'M' is for 'mum's the word' from me.
Categories: Offsite Blogs

Debugging complex map/filter chains

Haskell on Reddit - Thu, 04/10/2014 - 8:27pm

Sometimes, I have a bug in a complex map and filter chain, such as a wrong value coming out the end, or a value that should have filtered remains in the list. How do you deal with this? I've been creating a pair of the value and itself, so that I can see which input resulted in the wrong output, then rewriting my chain to work on the first element of a tuple, but this is tedious. Is there a better way?

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

Code review/Critique my first haskell program (game of life)

Haskell on Reddit - Thu, 04/10/2014 - 11:13am

Hello guys,

I just wrote my first "real" haskell program: a game of life implementation. Would anyone be willing to critique my code? it's here

Regarding the code:

  • I ran into trouble with IO (random and writeout)
  • I probably should have used a 2d array to represent the board
  • There are some performance issues (related to all the concatenations in the svg code?)

Any thoughts/comments are most welcome, please don't hold back! Thanks.


Thanks for the great comments everybody! I have started updating the code with the suggested changes. In particular: fixing the randomness bug, making evolution and writeboard "pure(r)" and simplifying functions.

I've updated the link above to point to the new version, the original code can be found here.

submitted by stmu
[link] [14 comments]
Categories: Incoming News

New gtk2hs 0.12.4 release

gtk2hs - Wed, 11/21/2012 - 12:56pm

Thanks to John Lato and Duncan Coutts for the latest bugfix release! The latest packages should be buildable on GHC 7.6, and the cairo package should behave a bit nicer in ghci on Windows. Thanks to all!


Categories: Incoming News