Expert to Expert: Erik Meijer and Anders Hejlsberg - The Future of C#
1) p = new Promise() creates a new promisePseudo code:
2) p.value <- val assigns val as the value of the promise
3) p.value returns the value of the promise, or blocks the thread if nobody assigned a value yet
class Promise<T> {You could implement a download function like this:
private T _value;
private handle;
public Promise() {
handle = new ManualResetEvent(false)
}
public T value {
get { handle.WaitOne(); return _value }
set { _value = value; handle.Set() }
}
}
download :: string -> Promise<Stream>Use it like this:
download url =
let p = new Promise()
let req = HttpWebRequest.Create(url)
req.BeginGetResponse(res => p.value <- res) // ommited boilerplate to extract the stream here
p
let page1 = download "foo.com"You can extract a pattern. If you have a value of type a, but the value is asynchronous (like a web page); it's really a function that you give a callback to:
let page2 = download "bar.com"
print page1.value
print page2.value
simple value: bSo it's a like a request in the above example: you don't have the actual web page, but you have a function that you can call (BeginGetResponse) and this function calls your callback when the web page arrives.
async value: Async<b> = (b -> ()) -> () // (b -> ()) is the callback
async :: Async<b> -> Promise<b>And implement download like this:
async ayncval =
let p = new Promise()
asyncval (val => p.value <- val)
p
download url = async HttpWebRequest.Create(url).BeginGetResponseOr if you don't support partial application:
download url = async (callback => HttpWebRequest.Create(url).BeginGetResponse(callback))Why did the F# team go for asynchronous workflows instead of this approach?
Given that reference variables can already be null or else point to something useful, don't they already have what is needed to represent the maybe monad? All that's lacking is the convenience of bind.
An extension method can act as the bind operation and that's all you need, isn't it? Or have I missed something (I'm relatively new to Haskell!)
Hello guys
this video on Perspectives on Functional Programming aside from being as totaly interesting as with all the other related videos had the nice thing of showing some recommended books to get more information on where to do more research on your own was fabulous.
I think it would be nice to add some way of letting c9 users to contribute on each videos pointing to other sources where to find information, like some webcasts, videos, articles, books (in the same post screen) so people can have a quicker access to other recommended
material and shorten the time spent in searching for the correct information on the internet.
Great work your doing, i find it fantastic
best regards
hec
I am into moving into functional programming (Haskell, F#) for the last few months. I have read Expert F#, Real World Haskell etc.
I am liking the ideas and styles and started coding some fun stuff with great things there in F#.
I was disappointed by the quality (succinctness and clarity) of this video compared to other numerous videos which I have seen from c9 or msdn. (Maybee worst of all which I have seen) Sorry, Matthew and Eric, but I missed the flow and stopped watching the video in the middle.
I am sorry if I am rude but I got one point from this lecture that intellisence is some kind of bad thing. The examples could have been given either in pseudo code (without any reference to syntax) or with correct syntax of either F# or Haskell.
does anyone know where i can find "Introduction to functional programming" book? amazon.com don't have.
Is this the correct ISBN #? 0134841891
cheers,
amir