Home
Ryan Ingram's Journal [entries|friends|calendar]
Ryan Ingram

[ userinfo | livejournal userinfo ]
[ calendar | livejournal calendar ]

Functional Reactive Programming [20 Apr 2008|06:11pm]
Recently I was reading Conal Elliott's draft paper Simply Efficient Functional Reactivity.

It's a great paper and his blog has a lot more information and a good introduction to FRP and what makes it interesting; better than I can write. Many implementations of FRP pay a big performance penalty communicating "nothing happened" between parts of the code and then re-evaluating results that can't possibly change. Conal instead flips the problem around and does data-driven evaluation: when events happen, they trigger re-evaluation of all data that depends on those events (which may include other events). Ideally, only data that needs to be recalculated is.Read more... )
8 comments|post comment

To pozorvlak [06 Feb 2008|08:00pm]
To [info]pozorvlak:

Can you please explain the section "Categorical Models of Type Theory" in the wikipedia entry on Intuitionistic Type Theory?

I understand (most) of the words on their own, but the sentences seem to just stop making sense to me as I read it.
5 comments|post comment

Haskell fun [14 Nov 2007|12:16pm]
I've been working on implementing games in Haskell. Specifically, rules-driven board/card games.

When these games run, they often need to ask a player to make a move. This involves interacting with the outside world in some way. The most obvious way to do this is to embed your computation in the IO Monad:

type Game a = IO a
-- or
type Game a = StateT GameState IO a


However, now you have the problem that arbitrary IO is expressible as part of a game action, which makes it harder to implement things like state tracking, replay, undo, and especially testing.

While thinking about this problem this morning, I came up with the following way to use existential types to split the game from its actions:

-- p is the type of prompts
-- r is the result type
data Prompt p r = forall a. Prompt (p a) (a -> r)
newtype Game a = Game (Either a (Prompt GamePrompt (Game a)))


So, Game t either immediately gives you a t to use, or gives you a prompt you need to reply to in order to continue the computation. Intuitively, I think this is related to the Continuation monad, but I'm not sure.

Now, a simple use of Prompt would be something like the following:

Prompt [1,3,5] (+1) :: Prompt [] Int

Code that sees this can't extract the values from the list, because they don't know the internal type of the list, but you could use it to implement something that randomly chooses:
chooseRandomly ::  RandomGen -> Prompt [] a -> (RandomGen, a)
chooseRandomly gen (Prompt xs f) = (gen', f x)
     where (gen', x) = choose gen xs

which uses the helper function choose :: RandomGen -> [a] -> (RandomGen, a)

This by itself is interesting and potentially useful, but where it really starts to shine is when the prompt type is a GADT:
-- a GamePrompt gives you the current game state,
-- which player needs to make a choice,
-- and a choice that player needs to make.
type GamePrompt a = (GameState, Player, GameChoice a)
data GameChoice a where
     Act :: GameChoice GamePiece -- what piece should act next
     Attack :: GamePiece -> GameChoice AttackType -- how should you attack?
     -- etc.

You can now define a prompting function:
prompt :: GameState -> Player -> GameChoice a -> Game a
prompt state who choice = Game $ Right $ Prompt (state,who,choice) $ \a -> Game $ Left a


and use it in the middle of game code:

turn :: GameState -> Player -> Game GameState
turn state who = do
-- ...
piece <- prompt state who Act
attackType <- prompt state who (Attack piece)
-- ...
return newState


Similarily, you can write a prompt handler which gets information from the user:

promptHandler :: GamePrompt a -> IO a
promptHandler (state, who, Act) = pickPiece state who
promptHandler (state, who, AttackType piece) = attackMenu state who piece
-- etc.


The neat thing about this is that on the right side of promptHandler, you know what type you need to return, since it's forced by the type of the GADT. What this means is that pickPiece can have the specialized type GameState -> Player -> IO GamePiece; it's no longer returning a generalized IO a (which is very difficult), but a specific type of object.

Now, in order to finish computing the GameState using promptHandler, you need to be in the IO monad, but there's nothing about the game that requires this! You could just as easily have a pure AI player promptHandlerAI :: GamePrompt a -> a

To tie it all together, you need a viewer function that gets the final result:

runGame :: (forall b. GamePrompt b -> IO b) -> Game a -> IO a
runGame _ (Game (Left result)) = return result
runGame f (Game (Right (Prompt prompt next))) = do
    action <- f prompt
    runGame f (next action)

runGameAI :: (forall b. GamePrompt b -> b) -> Game a -> a
runGameAI _ (Game (Left result)) = result
runGameAI f (Game (Right (Prompt prompt next))) = runGameAI f (next (f prompt))

Finally, to use any of this we need a Monad implementation for Game:
instance Monad Game where
    return a = Game (Left a)
    Game (Left a) >>= f = f a
    Game (Right (Prompt p fp)) >>= f = Game (Right (Prompt p next))
       where next x = fp x >>= f
10 comments|post comment

ICFP programming contest [29 May 2007|07:00pm]
I've been playing with the 2006 ICFP Programming Contest task. You have to write a virtual machine to the specifications given in the task, then use it to run the "codex" provided, which decompresses itself into another program. You then run that program on your VM and play around in the simulated "UMIX" OS. Pretty impressive work by the contest team, in my opinion.

You start out by logging into the guest account where you have access to a BASIC compiler (with a twist) and some broken sample code which the last guest apparently was using to try to hack the other passwords on the machine. As you work your way through the tasks, you get "publications" which are nonsense strings which you collect for points.

My favorite so far is the "2d" programming language in ohmega's account. Here's the given example, "plus.2d". The "plus" module adds the numbers supplied as its north and west inputs, where zero is represented as Inr () and x+1 is represented as Inl x. The test in main calculates 2+3.

       ,..............................|....................................,
       :plus                          |                                    :
       :  *==================*        |                                    :
       -->!send [(W,S),(W,E)]!--------#--------------------+               :
       :  *==================*        |                    |               :
       :         |                    |                    |               :
       :         |                    v                    v               :
       :         |                 *==============*    *============*      :
       :         |                 !case N of S, E!--->!send [(N,E)]!-------
       :         |                 *==============*    *============*      :
       :         |                        |                                :
       :         |                        v                                :
       :         |                    *========*       *================*  :
       :         +------------------->!use plus!------>!send [(Inl W,E)]!---
       :                              *========*       *================*  :
       ,...................................................................,


 ,..............................................................,
 :main                                                          :
 :                                                              :
 :  *================================================*          :
 :  !send [(Inl Inl Inl Inr (),E),(Inl Inl Inr (),S)]!--+       :
 :  *================================================*  |       :
 :                   |                                  v       :
 :                   |                            *========*    :
 :                   +--------------------------->!use plus!-----
 :                                                *========*    :
 ,..............................................................,

 % 2d plus.2d
 [2D] Parsing...
 [2D] Locating modules...
 [2D] Verifying wires in module 'plus'...
 [2D] Verifying wires in module 'main'...
 [2D] Connecting wires...
 [2D] Done Parsing!
 Result:
 Inl Inl Inl Inl Inl Inr ()


The adventure game in howie's account is pretty fun, too.

I've gotten the passwords for all of the accounts I can see in /home, and now I have a lot of puzzles to solve. It's a lot of fun even with nothing at stake.

If you want to play with it but can't get your VM working, let me know. I might make mine available somewhere.
post comment

cute [05 May 2005|04:27pm]
This is wayyy too cute... )
2 comments|post comment

The Republican Party are Pirates [29 Apr 2005|11:13am]
Not in the cute, happy, Puzzle Pirates sense of the word.

I was listening to a Dubya press conference last night, and he was very careful with his words to answer the questions given while not give the reporters any juicy sound bites that might undermine his policies. But he made a couple of key mistakes that an intelligent listener might pick up on.

1) "Arr! I'll compromise with ye and only take the booty from yer ship that we can fit in our hold!" He claims to want compromise on Social Security from the Dems but lists impossible conditions for that compromise. He wants no tax increase, continued benefits for existing members, and higher benefits for future members of the Social Security program. Given that it's already going broke (albeit slowly) at least one of those has to give.

2) "Swab the decks, lads, ye'll get as much as ye deserve, I swear it!" He was very careful to specify that future beneficiaries of Social Security would get at least the same benefits under his plan as current benefits. Of course, there was no mention of Cost of Living or inflation in that analysis... one wonders if "the same benefits" means the same cash amount, or the same quality of life.

3) "Har! Ship ahoy! Me mateys, we'll be eatin' hearty tonight from that poor ship o'er there." Personal retirement accounts, even if successful at providing benefits to their owners, are a gift to the credit industry. Dubya says, "We have a lot of debt," referring to individual consumers, and this was the point that resonated in my mind. Americans do have a lot of debt. And with no property to take to recover that debt, the credit industry has to suffer some losses for taking advantage of people who are unable to make sound financial decisions in their life. But if those people all had a personal account that they had paid into, then there would be plenty of cash to plunder. Given the bankruptcy "reform" taking place, this amounts to a massive gift to the credit industry. Do they really need more encouragement to continue sending out credit applications to people with no money, to take advantage of impulsive mistakes and desperate situations?

Finally, analysis of the cash flow in this country clearly shows taxes flowing from dense, highly populated "blue" states into the federal government and out into less populated "red" states. With rules (or threats to create rules) in Congress that would basically co-opt any power held by the minority party, I think it's time to start the "No taxation without representation" cry once again.

In particular, I'm tired of the economic success of the S.S. California being plundered by the Jolly Roger of Middle America. I propose that legislation be introduced in California which co-opts the federal income tax. We can calculate what percentage of the US income tax that our citizens would be paying into the system, and what percentage of benefits we expect to get out of it, and reduce our payments to the feds appropriately. The extra money would either go into the state General Fund (budget problems solved!) or refunded to individual taxpayers.

We can fight the pirates! Our cannons are as good as theirs, and our swords twice as sharp!
1 comment|post comment

[29 Mar 2005|02:02pm]
For [info]zqfmbg:

Your very own Vanity Domain Name
1 comment|post comment

Our President [04 Mar 2005|05:02pm]
I heard a quote from Dubya on the radio today. It went something like this.

"We support the growing democracy in Lebanon, and it cannot succeed while being occupied by a foreign power. And that power is Syria."

I just started laughing, and laughing, and laughing.

You see, in my head, he said this:

"We support the growing democracy in Lebanon Iraq, and it cannot succeed while being occupied by a foreign power. And that power is Syria the United States."
2 comments|post comment

Crash! [17 Dec 2004|03:47pm]
I was about to leave today, when there was a loud noise outside.

There was a big accident at the intersection of 16th and Church. An SUV ran a red light and either hit or was hit by another car in the intersection. The SUV deflected onto the sidewalk, into one of the city public garbage cans (probably at least 200 lbs of weight, there), and into my house. Fortunately, nobody was hurt.

It doesn't look like there is any real damage to the house... just black paint scraping. But, wow.

I spent the next half-hour collecting insurance information and phone numbers from the drivers, and dumped a copy of that into the mailbox of our downstairs neighbor who is currently HOA president.

Crazy.
3 comments|post comment

A story [13 Dec 2004|03:45pm]
Once there was a little company called Rockstar Games. They made a game called Grand Theft Auto, and it was good, and the people were happy.

Then a company called Take Two Interactive bought Rockstar. They made State of Emergency, and it was really bad, and the people were worried. But then they made Grand Theft Auto Vice City and the people's fears were assuaged.

There was also a giant named EA. EA made a game called Madden NFL Football. It was a good game, most people thought, and people kept buying it every year or two, for $50. Some people wondered why people kept buying it, but they did. And EA was happy, and the people were mostly happy.

Then Take Two made a game called ESPN NFL 2K5. It wasn't as good as the previous football titles, like Madden, but they only wanted $20 for it. Some people cheered. Others booed. Others didn't know what to make of it all.

But Take Two made the giant very angry. And the angry giant went to the NFL and said, "Lo! ESPN NFL makes me very angry! We have to do something about it."

And they did.

I'm not sure if the people lived happily ever after or not.
2 comments|post comment

[08 Dec 2004|01:38pm]
Things that have gone wrong lately. All of these things are projects I need to handle myself or manage.
See all my problems )
3 comments|post comment

DDR Thursday [30 Jul 2004|03:03pm]
[ mood | calm ]

DDR Thursday actually happened on Thursday this week.

Significant accomplishments:
- 7 greats on Kind Lady heavy (all other steps Perfect)
- 10 greats on Colors heavy
- Passed Soul 6 again (I haven't passed a Challenge course in a while). 3 non-combo steps.

[info]zqfmbg was ahead of me on score for most of the course but he failed on Hysteria Challenge. I'm pretty confident that, had he finished, he would have been 50-100 points ahead of me.

Anyways, it was fun. It was also way more crowded than usual. Met a new nice guy there, named Edwin. Out of work (I think) sales/finance guy, who seemed pretty interested in EA. I told him I'd try and find a contact person for him. Which reminds me, I need to do that.

We're going back out house-hunting again this weekend. I hope we find a few nice places.

1 comment|post comment

condo foo [29 Jul 2004|02:19pm]
[ mood | cranky ]

I took the day off of work yesterday to put a last-minute offer in on a condo that Carisa and I really liked, on 19th and Guererro. It was only a one-bedroom place, but it was big, and it had a quarter bathroom which would have been perfect for the cats to use. They were supposed to take offers next week, so I had been planning to put an offer together over the weekend, but we found out someone had put in an early offer so we had to scramble.

We offered almost $100k over the asking price, and found out less than three hours later that we weren't even in the running.

The housing market here doesn't make any sense. Why even HAVE an asking price if it's totally irrelevant to the offers you take?

3 comments|post comment

Tuesday Food [10 Jun 2004|10:52am]
[ mood | jubilant ]

I made Chicken Kiev for Tuesday dinner this week. It turned out very well.

Here's the recipe I used. I took the parts I liked from a bunch of recipes around the web and put them together, modifying slightly to fit the ingredients I had around the house.

Filling (for 4 servings):
4 tbsp butter (1/2 stick)
1/2 tsp ground black pepper
1 tsp minced garlic

1) Soften the butter by leaving it at room temperature for ~20 minutes.
2) Mix all ingredients in a mixing bowl until well blended
3) Wrap (I used a zip-lock bag), form into a small rectangle, and freeze to re-harden.

Most recipes say to freeze for at least 30 minutes, but I left it overnight since I did this part the night before. If I did it again, I would split the butter into one-serving-size pieces while it's still soft, before freezing it. I'd also use 1/4 tsp pepper instead of 1/2, and perhaps add some other seasoning.

Chicken Kiev:
4 tbsp butter (1/2 stick)
4 boneless skinless chicken breasts
Filling (above)
2/3 cup plain bread crumbs
1/4 tsp salt
1/4 tsp dried thyme leaves
1/8 tsp black pepper
1 to 2 tbsp chopped parsley

1) Preheat oven to 350 degrees F
2) Flatten chicken breasts to ~1/4" thickness by pounding between two sheets of wax paper (I used my fist, but a mallet or rolling pin would work better)
3) Place one portion of the frozen filling onto each chicken breast, and roll up. Tuck in the edges of the chicken (this was difficult), secure with toothpicks.
4) Melt the butter in an 8" square baking dish in the oven (takes about 5 minutes).
5) While the butter is melting, combine bread crumbs, salt, pepper, thyme, and parsley in a small mixing bowl.
6) Take the butter out of the oven. Dip chicken breasts in melted butter, then roll them in the crumb mixture.
7) Put the chicken in the baking dish (with the remainder of the butter still there). Cook for 1 hour at 350 degrees
8) Make sure you don't eat the toothpicks.

The recipe I had said to remove the toothpicks before serving. I had semi-small toothpicks, though, and after rolling the chicken in the breading they were sometimes embedded. So I just warned everyone to take them out while eating.

It was really good.

post comment

Guest Entry [20 Mar 2004|11:40pm]
[ mood | Carisa-y ]

This guest entry in ryani is brought to you by Carisa; yes, Carisa, as in Carisa of Ryan and Carisa, also known as Carisa of other-livejournal-username-not-allowed-to-mention-here.

As I've asked Ryan to write an entry in my LJ, he decided to ask me in return. I will try to write this entry in the style of Ryan's LJ... So here goes:

I volunteer at the SPCA now, and I just went to my first cat show today. I mention the SPCA volunteering because it helped me get more and more re-familiarized with cat breeds before attending the show (which I'd just found out about earlier in the week).

Here's how the place was set up -- little tables all in rows. On the tables were cats, in their show carriers, and then there were judging "corners" in the center of the building. And lastly, there were merchant booths with hordes and hordes of cat stuff (furniture, beds, carriers, T-shirts, toys, food, even kitty litter).

(Now, if this entry were in the true style Ryan's LJ, it wouldn't include this paragraph or the one before it or any of the following paragraphs because it'd be done already... I'm a tad wordier than Ryan).

I watched one judging round where the judge was looking at kittens (they must be at least 4 months old to compete). I saw a couple kittens earlier and thought they were just petite cats, so when I saw them again at the "Best Kitten" judging booth, I was shocked that they were still kittens. It was interesting to see how all that crazy cat fancier stuff happens.

I ended up buying only one thing -- a cat toy, made of a peacock feather. It's gorgeous. I was almost afraid to give it to Maxine to play with (supervised, of course). I got more ideas on how to make cat furniture, and found out the selling price of comparable cat beds (which I hand-sew).

1 comment|post comment

Tim eats with chopsticks [20 Mar 2004|11:15pm]
[ mood | amused ]

As I mentioned to Carisa and Tim the other night when we went to Chow, I said I would write in my journal about the bet.

I bet Tim couldn't eat his lasagna with chopsticks as his only utensils. We all decided that eating the bread with his fingers was acceptable, but everything else was with chopsticks. If Tim succeeded, I'd buy his drink for him.

I had to pay for Tim's $3 lemonade. It was well worth it.

post comment

Happy Anniversary [15 Mar 2004|10:45am]
[ mood | giddy ]

Beware the Ides of March. Because that's my anniversary.

Thanks for being such a great person to be with, Carisa. I love you!

3 comments|post comment

home development [24 Feb 2004|03:43pm]
I spent a bunch of time setting up my home PS2 for development. I got a network adapter for it, and set up a memory card with the "ps2-independence" hack so I can boot off of memory card.

I have a bootloader client and gcc-based toolchain that I got off of ps2dev.org and put everything together.

I spend a couple of evenings tracking down some documentation on the web and writing up header files that let me easily twiddle the hardware's bits.

So, considering that I'm a pretty experienced PS2 developer, I write a quick program to initialize the graphics hardware and clear the screen to some color. And it doesn't work. It doesn't clear the screen, it doesn't do anything. I add a bunch of code to print out what I'm sending to the hardware and it all looks okay.

I spend two nights trying to figure out why it doesn't work, and then I finally realize that the bootloader left an open graphics command packet and it was just sitting waiting for more data from that source, and my data never got through. Stupid bootloader authors, writing buggy code.

Anyways, now that I fixed that, I can work on making my own games. Maybe I'll try to write a Java VM and port puzzle pirates!
4 comments|post comment

Darn [14 Nov 2003|02:38pm]
I owe [info]xtalcy a dollar.
1 comment|post comment

Recommendations? [20 Oct 2003|10:41am]
I'm looking for a Japanese GameBoy Advance game, or, failing that, PS1, that has a lot of dialogue but at a fairly low grade-level.

Any suggestions*?

On another note, I made it through 7 songs of the Ultimate 12 Nonstop before I gave up. That's four catas in a row, including Kakumei on Reverse!

- Radical Faith (8)
- Vanity Angel (8)
- SP-Trip Machine (8)
- Tsugaru (9)
- Afronova (9) (I was surprised I could still move after finishing this)
- PARANOiA kcet (9)
- Kakumei (reverse) (9)

I didn't even start the next song (Hysteria), I just went to get something to drink. :)

*Extra bonus points if your name is Crystal and you have said GBA game available for me to borrow.
post comment

navigation
[ viewing | most recent entries ]
[ go | earlier ]