News for hackers. Stuff that matters.

Martijn

Re:Ask HN: Are there any startups making desktop apps? on Wednesday April 29, 2015 @11:37AM (#9459061)
You're in the wrong thread. :-)

But to answer your question anyway, this is the responsible line of code: https://github.com/marekdlugos/TakeMeAsIntern/blob/master/as...

Re:Detecting use cases for GADTs in OCaml on Monday January 12, 2015 @05:10AM (#8873116)
It's a combination of avoiding potential bugs and just modelling things differently altogether:

If I had to leave out the answer type of questions, I'd have to come up with an entirely different way of modelling answers. For example, I might have had to write a datatype like:

  data Answer = AnswerBool Bool | AnswerInt Int | ...
and then processing the answer (through pattern matching) would have to discard any answer it didn't like, which is awkward. Or I would have had to use a type class to keep everything type-safe which would have resulted in more complicated type signatures throughout the code.

For the TargetList, the current setup allows me to write functions that consume a target list of exactly the right size, for example:

  \(target1, target2) -> ...
rather than a normal list:

  \[target1, target2] -> ...
which in this case results in a pattern match exception if you pass it a list of any length other than 2.
Re:Detecting use cases for GADTs in OCaml on Wednesday January 07, 2015 @08:38AM (#8850382)
My Magic: the Gathering implementation uses a few GADTs. Interestingly they use GADTs in very different ways. Source code is here: https://github.com/MedeaMelana/Magic/blob/master/Magic/src/M...

Let me briefly highlight three of them:

1) Type Question models questions that the game might ask of players. Its constructors are tagged with the type of the answer to that question:

  data Question a where
    AskKeepHand :: Question Bool
    AskTarget   :: [EntityRef] -> Question EntityRef
    ...
This allows me to write cards that ask questions and later on plug in various interpreters of these questions (command line interface, JSON webserver, AI, test framework).

2) The ZoneRef datatype enumerates the various zones in a game of Magic (battlefield, hand, etc) but I've chosen to tag each ZoneRef constructor with a type that indicates what the type of a card is when you look up a reference to a card ("object" in Magic jargon):

  type ObjectRef ty = (ZoneRef ty, Id)
  lookupObject :: ObjectRef ty -> Magic (ObjectOfType ty)
Most functions that take object references as an argument like to constrain the type of the object referenced, and using a GADT allows them to do so. For example, dealing damage to an object (creature or planeswalker):

  data SimpleOneShotEffect = DamageObject Object (ObjectRef TyPermanent) Int ...
3) Type TargetList models zero or more targets a spell on the stack can target. Even though in essence it is just a list of targets, it is a GADT so that it can have a "return type" which is re-evaluated when one of more of the targets change (for example, by a card like Redirect or Reverberate).

Hope this helps!

If I remember correctly the automatically sorting through your pictures and picking the best is exactly what Google announced for Google+ at their last I/O keynote.
Re:From zero to cooperative threads in 33 lines of Haskell on Tuesday June 25, 2013 @06:09AM (#5938448)
You don't really need to understand all these things in order to build "real" things with it. Just build something without caring too much whether an experienced Haskell programmer would find it elegant enough.

Most of the "clicks" I've had is when I'd already built something in a naive way (that worked perfectly) and someone showed me an alternative, more elegant way in which it could be written.

I wonder if this is also true if you are a foreigner visiting the US.

And I wonder if this also works for the Dutch police.

Re:Today's Email Incident on Wednesday March 20, 2013 @08:20AM (#5406753)
What company in Portugal do you work for?
Re:The If-by-whiskey fallacy on Thursday January 17, 2013 @08:19AM (#5072420)
For some reason this reminds me of Quine Central[1]. :-)

[1] http://blog.sigfpe.com/2011/01/quine-central.html

Re:Understanding map, filter, and fold on Monday December 24, 2012 @04:59AM (#4962410)
Not really. There's a really nice paper by Graham Hutton, "A tutorial on the universality and expressiveness of fold" which goes into a bit more depth than OP does. Your question is answered directly in section 3.2, "The fusion property of fold". Basically, a sequence of multiple folds can be fused to a single fold.

See http://www.cs.nott.ac.uk/~gmh/fold.pdf

Re:Why learning Haskell makes you a better programmer on Monday December 24, 2012 @04:25AM (#4962359)
> > boo :: Map Integer String -> String -> Integer

> This syntax is clean but it doesn't tell me anything that

> def boo(map: Map[Integer, String], key: String) : Integer

> doesn't tell me.

OP's point was not so much that the Haskell syntax is clean, but more that there is a huge difference between

Map Integer String -> String -> Integer

and

Map Integer String -> String -> IO Integer

The latter is allowed to do IO, while the former is not. There are very few languages that allow you to express this difference and have the compiler enforce it (Haskell being one of them). So "Map Integer String -> String -> Integer" tells you a lot more than "def boo(map: Map[Integer, String], key: String) : Integer" does.

For more information about what exactly types tell you, look up parametricity or read Philip Wadler's "Theorems for free".

Re:A Vote for CSS Variables on Tuesday March 20, 2012 @10:58AM (#3729548)
In Haskell variables are called variables because they potentially have a different value each time the function is called.

See also Variable (mathematics) [1] vs. Variable (computer science) [2].

[1] https://secure.wikimedia.org/wikipedia/en/wiki/Variable_%28m... [2] https://secure.wikimedia.org/wikipedia/en/wiki/Variable_%28c...

Re:How I Beat Repetitive Stress Injury on Sunday February 26, 2012 @05:41PM (#3637040)
Can you tell us more about the book? Would you recommend it? Is it easily accessible?
Re:Learn from Haskell - Functional, Reusable JavaScript on Tuesday February 21, 2012 @04:20AM (#3615820)
Small nitpick, the type of forever is actually:

  forever :: Monad m => m a -> m b
Since it never returns a value, the resulting monadic action can be polymorphic in its return type.
Re:The man who hears colour on Friday February 17, 2012 @05:18AM (#3602826)
Is the color->note map arbitrary or is there some logic behind it? I imagine it greatly affects the associations (including emotions) he has built up over the years.
Re:A Programming Idiom You've Never Heard Of on Wednesday January 04, 2012 @05:33AM (#3423570)
Also:

  identity = Invertible id id
Re:John Carmack on the importance of Static Code Analysis on Saturday December 24, 2011 @01:31PM (#3389351)
Don Stewart on undefined vs. null: http://stackoverflow.com/a/3963464/17439
Re:Hacking Christmas lights on Thursday September 08, 2011 @06:52AM (#2973354)
http://www.evilmadscientist.com/ has lots more of this stuff if you are interested in it.
Re:Shake to Undo (for Mac OS X) on Wednesday September 07, 2011 @04:30AM (#2968800)
If Braid is in your top three, I'm curious: what other games do you really like?
Re:Markdown.css: let's make the Web prettier on Sunday July 31, 2011 @06:20AM (#2828056)
Is it just me or should the bullets and numbers of the lists be indented?
FF on Mac actually tries to do something clever here. It won't start scrolling the page itself until after a small delay or until you move the mouse.
Re:Why your company should do an internal hackathon on Saturday July 09, 2011 @11:55AM (#2745767)
At Q42, the company I work for, we have a yearly hackathon. We start Friday morning and then depending on individual circumstances work until anywhere from Friday night to Sunday night.

We've covered last November's hackathon on tumblr: http://w00tcamp.tumblr.com/

One of the resulting projects is http://www.soundmatch.me/ -- enter your Last.fm username and it will generate a Spotify playlist based on your music recommendations.

Re:Interesting C code on Friday July 08, 2011 @10:22AM (#2742497)
Warnings are to be expected if your goal is to make your program as short as possible.
I wonder if it matters whether people are using their trackpad. I was using mine and immediately figured it out; maybe it's because scrolling horizontally is trivial with a trackpad?
Re:Convince your boss to let you use Scala on Friday July 01, 2011 @10:12AM (#2718387)
Good bosses also want happy employees.
Re:Mysterious number 6174 on Tuesday June 07, 2011 @04:35AM (#2628350)
This reminds me of a beautiful and appropriate comic by Cowbirds in Love:

http://cowbirdsinlove.com/43

Re:Types Are Anti-Modular on Monday June 06, 2011 @07:41AM (#2624349)
> (...) in an untyped language, you can run code that doesn't depend on the missing APIs but happens to be in the same module as code that does depend on them.

So this advantage is about writing code that isn't intended to be compiled or run yet. I can do that in a statically typed language too: I just put the code in a comment block.

Or am I missing something here?

Re:What happens when a Social Game - is run with Bots? on Sunday June 05, 2011 @06:45AM (#2621768)
Reverse Ender's Game.