Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Tuesday, April 27, 2010

F# weirdness of the day...

I have a piece of code that says:
links
    |> Seq.map (fun x -> x.GetAttributeValue ("href", "no url"))

Which I wanted to rewrite to "the other syntax" accepted by F#:
links
    |> Seq.map (fun x -> (x.GetAttributeValue "href" "no url"))

But I have no luck. The amusing thing is the error message I get from Visual Studio:
The member or object constructor 'GetAttributeValue' taking 2 arguments are not accessible from this code location. All accessible versions of method 'GetAttributeValue' take 2 arguments.
Say what?

[p.s. I posted this to Stack Overflow to in hopes of getting a bit of wisdom. Check there for possible answers.]

Getting all a hrefs from a webpage -- F# warm-ups

Been needing this for quite some time, and decided it was about time to tackle it as a way to flex my F# muscles a bit. I wanted to make this a command line utility, but haven't gotten around to it yet. If I do, I'll have it consume the html from STDIN, and spit the links to STDOUT. I want to do it that way to allow flexibility in how the pages are fetched.

Here is the code:

Monday, April 12, 2010

OO's N-levels of indirection

OO relly frustrates the daylights out of me sometimes.  You find a function that gets passed an IThing, which has referectes to other IThingies.  In working with some code, you find there there is a call to an IThing.IThingy.Foo, and you try to determine which piece of code is responsible for it.  Good luck.

This anoying trip ussually starts with trying to figure out what classes implement which interfaces,  something that VS2010 still doesn't seem to make trivial (maybe my Kung fu is just not strong).  Trusty Reflector to the rescue.  If you are lucky, there is only one implementor, and this journey is over.  If you are not lucky, you get to try to traverse the call stack, to see which implementation got instantiated and passed to the function at hand.  If your are completely unlucky, there is a dynamic (i.e. reflection) call somewhere in there, at which point your brain segfaults.