Better HN
topnewbestaskshowjobs
Log inSign up

Martijn

72 karma · joined May 13, 2011 (15y ago) · 29 submissions

Submissions

comment 11y ago · link · parent

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...

comment 11y ago · link · parent

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.

comment 11y ago · link · parent

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!

comment 13y ago · link · parent

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.

comment 13y ago · link · parent

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.

comment 13y ago · link · parent

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.

comment 13y ago · link · parent

What company in Portugal do you work for?

comment 13y ago · link · parent

For some reason this reminds me of Quine Central[1]. :-)

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

comment 13y ago · link · parent

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

comment 13y ago · link · parent

> > 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".

comment 14y ago · link · parent

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...

comment 14y ago · link · parent

Can you tell us more about the book? Would you recommend it? Is it easily accessible?

comment 14y ago · link · parent

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.

comment 14y ago · link · parent

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.

comment 14y ago · link · parent

Also:

  identity = Invertible id id

comment 14y ago · link · parent

Don Stewart on undefined vs. null: http://stackoverflow.com/a/3963464/17439

comment 15y ago · link · parent

http://www.evilmadscientist.com/ has lots more of this stuff if you are interested in it.

comment 15y ago · link · parent

It was called SmackBook:

http://blog.medallia.com/2006/05/smacbook_pro.html

comment 15y ago · link · parent

If Braid is in your top three, I'm curious: what other games do you really like?

comment 15y ago · link · parent

Is it just me or should the bullets and numbers of the lists be indented?

comment 15y ago · link · parent

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.

22.

Last.fm Blog: Library and streaming services outage(blog.last.fm ↗)

2 points · by Martijn · 15y ago · discuss

comment 15y ago · link · parent

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.

comment 15y ago · link · parent

Warnings are to be expected if your goal is to make your program as short as possible.

comment 15y ago · link · parent

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?

comment 15y ago · link · parent

Good bosses also want happy employees.

comment 15y ago · link · parent

This reminds me of a beautiful and appropriate comic by Cowbirds in Love:

http://cowbirdsinlove.com/43

comment 15y ago · link · parent

> (...) 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?

comment 15y ago · link · parent

Reverse Ender's Game.