|
|
Warp wrote:
> Now you'll have to implement the same program in C++. ;)
Yes. That'll be harder, of course - I don't know the standard library
for C++ inside-out yet. ;-)
I know you probably won't care, but take a look at this:
http://haskell.org/hoogle/
Now, suppose I want a function that takes a String and turns it into an
Integer. If you type in
String -> Integer
and hit the search button, the very first result is
Prelude.read :: (Read a) => String -> a
(base)
Which tells you that the "Prelude" module (implicitly imported by all
Haskell modules) contains a function named "read", which will transform
a String into any type "a" that is a memory of the "Read" class. (And it
turns out that *all* the basic types are members of this class.)
Similarly, suppose I want to, say, discover whether a given list
contains a specified element. Well, the function that does that is
obviously going to take two arguments - a list, and a thing to find.
Slightly less obviously, you can only do this for types that can be
compared. In Haskell, that means types that belong to the
cryptically-named "Eq" class. So we have
(Eq x) => [x] -> x -> Bool
A quick search, and we get
Prelude.elem :: (Eq a) => a -> [a] -> Bool
(base)
Notice how the arguments are actually the other way round, but the
search still found the function. (You can also search by name - useful
if you find yourself asking something like "dude, WTF is 'nub' supposed
to be?!")
You might not care about Haskell, but you gotta admit all of this is
pretty neat, eh?
Now, the question is... is there a similar resource for C++? Because for
starters, the first thing I'm gonna want to know is how to choose a
random number in C++. ;-) (Altough I dare say for *that*, a simple
Google search will probably answer...)
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|