Not sure if this is the right subreddit for this, but I thought I'd share - I wrote this little poem for my girlfriend on Valentines day:-- You're one in a million, you = 1 everyoneElse = 999999 -- And I promise I'll stay True == -- And that while you'll take me, takeWhile -- I'll love only you (<3) [you, everyoneElse] == [you]
Of course, the Haskell is supposed to be:you = 1 everyoneElse = 999999 *Load into GHCi* > True == (takeWhile (<3) [you, everyoneElse] == [you])
It's not perfect, but I like it :)submitted by Daejo
[link] [21 comments]
That is to say, if A + B is a type that contains either A or B, and A * B is a type that contains both A and B, then what is A (X) B where (X) is the tensor product, or does it not exist?submitted by gcross
[link] [8 comments]
If you want to read more about the ICFP Programming contest, you should have a look at our report about it.
You can order a t-shirt with the after picture on the back, and one picture from the arrival sequence on the front from cafepress, or create your own t-shirt using these materials (4.3MB).
If you want to see the presentation we gave about the contest at ICFP 2007, have a look at our video (with an explanation about how to solve the contest problem starting at 18:00, and Endo appearing at around 1:12:00).
The question we got after the contest was: How much time did you spend creating it? We have different answers to this question, but probably the one that comes closest to the truth is: as much as we enjoyed creating it.
I'm not really sure if this pattern has a name, but it occured to me a few days ago and I've just been thinking about this, but haven't really used it.
Say that you have a function magic which accepts a CreditCard type and does some magic with it. At that point you really expect the card to be already validated (which happens up in the call stack). But since the CreditCard type is just a value, it doesn't carry around the context having passed validation.
Just to make this clear, I'm not talking about simple string validation, but something like checking with a payment gateway and making a $0 transaction, to actually check that the card is valid. Think of this example as something you only want to validate once.
Now we've established that the magic function should never be called with a raw CreditCard that hasn't been through the validation, a program that does such thing shouldn't even compile, right?
The thing I came up with is to use a newtype wrapper, something like newtype Valid a = Valid a, so that I can then have the function type defined as magic :: Valid CreditCard -> IO ().
This way when I get a new CreditCard from a user or something, I can run it through a validation which would return either a Valid CreditCard, or some error. For example validate :: CreditCard -> Either ValidationError (Valid CreditCard).
What do you guys think about this? Do you do this? Does it make sense? Does it have a name?submitted by progfu
[link] [9 comments]
Hi! Today I decided to present something I’ve been wandering around for some days now.
The initial problem is this:
Given a context with values, how could we react to a change in that context?
I came up with a very small solution, but that works well for me. Here’s a lpast link to my idea – I’ll make a package later if we find it cool and sexy.
The idea: you have two concepts: the monad you want to react to (m), and the monad you want to react in (r). When something happens in m, something should happen in r. We can state that m is observed by r. It’s then quite simple: my library provides a way to wrap monadic functions in the observed monad into the observer so that when such a function is called, the observer reacts.
I know FRP, and I know it’s great, but I wanted to present something way simpler, for not-that simpler problems.
What do you think folks? Should I make a monad-reactive package, or do you think it’s worthless?submitted by _skp
[link] [13 comments]
I'm currently working on language-gcl, a library that currently doesn't do much more than implement Dijkstra's guarded command language (GCL). GCL only defines two 'building blocks' of a programming language, because the manuscript it's defined in (EWD 418) focuses mostly on formal methods.
The building blocks of GCL are the alternative construct (if ... fi) and the repetitive construct (do ... od), which contain guarded commands. Dijkstra doesn't define the expression language (except that the guards must be decidable predicates) and explicitly leaves room for 'other statements'; he uses examples of (concurrent) assignment, e.g.:if true -> x := Y; y := Y; do x > y -> x := x - y  y > x -> x, y := y, x od fi
So anything if...fi or do...od is defined by GCL, but everything else (the guard expressions, the assignment statements) is up to whoever uses GCL.
So I decided to start with this:data GCL stmt guard = Alternative [GC stmt guard] | Repetitive [GC stmt guard] | Statement stmt data GC stmt guard = GC guard [GCL stmt guard]
This allows for some extensibility, such as concurrent assignment, assert and assume statements, and many other things.
I ran into problems with the extensibility on two distinct occasions. One involved adding loop invariants (type parameter explosion!), but I believe that my current solution (adding a [guard] field to Repetitive) is reasonable.
The other is a little more problematic, which (initially) involves declaring variables. If I want to extend GCL with any constructs that may contain more GCL, I run into knot-tying problems. Ideally, I want to simply define something like this:data Variables name ty expr = Declare [(name, ty)] gcl | Assign [(name, expr)]
I could end this right here, with (gcl ~ GCL (MoreStmts name ty expr) expr), but this doesn't really sit right with me, DRY being one problem:data Exceptions gcl = Raise | Rescue gcl gcl
It would also be really nice to be able to spice things up à la carte, e.g. GCL (Exceptions :+: Variables name ty expr) expr, but I would lose that by using this solution.
So, to tie the knot, I could make gcl the last type variable of MoreStmts and introduce the horrific nice auxiliary typenewtype GclKnot stmt1 guard = GclKnot (GCL (stmt1 (GclKnot stmt1 guard)) guard)
but I fear the doubling of type variables will get me into all sorts of trouble once I want to use these things with type classes. I can also forget about deriving any instances.
Does anyone have an idea for improvement? Or am I trying too hard?submitted by Rhymoid
[link] [6 comments]