NetStudent.cz - články v kategorii Programovací jazyky http://netstudent.cz/Articles/?tag=programovaci-jazyky&author= Nejnovější články na webu NetStudent.cz v kategorii Programovací jazyky Tue, 28 May 2024 22:20:11 +0200 69e151b9-9f0c-4468-903e-ec5c87fdbc2a http://dajbych.net/windows-8-nove-s-winrt Václav Dajbych Windows 8 nově s WinRT Windows 8 obsahuje nové API, Windows Runtime, které dovoluje používat HTML ke stejnému účelu jako XAML a JavaScript k totožnému záměru jako C#. Fri, 16 Sep 2024 00:00:00 +0200 dfa07d5a-e71a-438e-9e77-1b88db02edfe http://penzes.cz/blog/programovani/2011/07/jak-implementovat-inotifypropertychanged/ Jirka Pénzeš Jak implementovat INotifyPropertyChanged Na následujících několika řádcích se vás pokusím seznámit s velice užitečným a mocným rozhraním. Řeč bude o rozhraní INotifyPropertyChanged, které je obsažené v Systém.ComponentModel.Konkrétně se podíváme na různé způsoby implementace v jazyce C#. Sun, 24 Jul 2024 00:00:00 +0200 06bd3299-bfce-40cb-8937-5446d71034ff http://penzes.cz/blog/programovani/2011/01/prace-s-pameti-a-ukazatele-v-c-net/ Jirka Pénzeš Práce s pamětí a ukazatele v C#.NET Adresy, ukazatele, alokace, dealokace a další podobná slovíčka jsou typicky spojovány převážně s jazyky C a C++. Ve vyšších programovacích jazycích, jako je třeba Java a C#, se touto „neoblíbenou“ částí programování vůbec nezabýváte. Otázkou by mohlo být, zda to vůbec lze. Můžeme v jazyce C# deklarovat ukazatele nebo ručně alokovat určitý kus paměti? Jde to. Tue, 01 Feb 2025 00:00:00 +0100 8b236132-bb43-4e15-8057-34b56855d2b8 http://dotnetplatform.cz/Clanky/2010/9/23/18~Paralelni-programovani-v-NET-4-0 Jirka Pénzeš Paralelní programování v .NET 4.0 Ve světě, kde už téměř standardem mít počítač s více-jádrovým procesorem, už není takovým pravidlem, že by vývojáři aplikací tento fakt brali v potaz. Aby aplikace dokázala využívat efektivitu více-jádrových procesorů, je zapotřebí, aby programátor uměl pracovat s vlákny. Fri, 24 Sep 2024 00:00:00 +0200 57ad4c11-41fa-4b4d-a698-23f4871713c5 http://netstudent.cz/Articles/wcf-pro-zacatecniky-8-dil-autentizace-podruhe Kryštof Laryš WCF pro začátečníky – 8. díl: Autentizace podruhé Možností, jak implementovat autentizaci ve WCF je hned několik. My si popíšeme dvě z nich. Autentizaci pomocí ASP.NET Membership Provider a Custom Membership Provider. V tomto díle to bude Custom Membership Provider. V díle minulém to byl ASP.NET Membership Provider. Thu, 16 Sep 2024 00:00:00 +0200 9cd1f39c-b8ad-426b-84f5-0d825b0b8492 http://netstudent.cz/Articles/wcf-pro-zacatecniky-7-dil-autentizace-poprve Kryštof Laryš WCF pro začátečníky – 7. díl: Autentizace poprvé Možností, jak implementovat autentizaci ve WCF je hned několik. My si popíšeme dvě z nich. Autentizaci pomocí ASP.NET Membership Provider a Custom Membership Provider. V tomto díle to bude ASP.NET Membership Provider. V příštím díle to bude Custom Membership Provider. Wed, 15 Sep 2024 00:00:00 +0200 d4c940a6-5026-4f93-a94f-9e705261c142 http://dotnetplatform.cz/Clanky/2010/9/2/17~Navrhovy-vzor-Kompozit-Composite Jirka Pénzeš Návrhový vzor Kompozit (Composite) Dalším návrhovým vzorem, na který se podíváme, je vzor Kompozit (Composite). Jedná se o ucelené řešení, jak uspořádat objekty v aplikaci. Myšlenka vzoru je vytvořit hierarchickou strukturu z objektů, kde ke skupině objektů a samotnému objektu přistupujeme stejným způsobem. Na tento vzor lze pohlížet jako na stromovou strukturu dat. Typickým příkladem je například průzkumník ve Windows. Thu, 02 Sep 2024 15:00:00 +0200 1dbfc9b4-ea12-423f-b310-208ecab64577 http://xaml.cz/wpf/geometrie-ve-wpf/ Jirka Pénzeš Geometrie ve WPF Pro potřebu vykreslování 2D geometrických útvarů je ve WPF připravena třída Shape. Z této třídy jsou odvozeny a připraveny pro práci objekty Ellipse, Line, Path, Polygon, Polyline a Rectangle. Pokud ale chceme nakreslit vlastní geometrický... Thu, 19 Aug 2024 00:00:00 +0200 8bfc3fde-bbcf-4ab6-b672-09f7bae4e780 http://www.vbnet.cz/clanek--167-rozhrani.aspx Tomáš Herceg Rozhraní V tomto díle si ukážeme, jak deklarovat a implementovat rozhraní a k čemu to vlastně je. Krátce si též představíme základní vestavěná rozhraní v .NET Frameworku.[Zobrazit článek] Mon, 19 Jul 2024 00:00:00 +0200 94f6456a-5d5b-4377-91a9-7b2b2e2d6e8d http://tomasp.net/blog/fsharp-mvc-web.aspx Tomáš Petříček ASP.NET and F# (I.) - Creating MVC web applications in F# Some time ago, I wrote a couple of examples of developing web applications in F# using ASP.NET. Since then, the F# language and runtime has changed a little bit and there are also new technologies available in ASP.NET, so I thought I'd write a more up-to-date article on this topic. In this article, I'll present a simple "demo" F# web application that you can use as a starting point when creating your own projects (you'll also find a convenient Visual Studio 2010 template below). The article shows the following interesting things: ASP.NET MVC - We're going to use ASP.NET MVC Framework to create the web application. As the article name suggests, most of the actual program code including models and controllers will be implemented in F#. F# LINQ to SQL - The application uses a sample Northwind database and we'll write queries for selecting data from the database using LINQ support that's available in the F# PowerPack. F# features - The application also uses some nice F# features that are quite useful for developing web applications. We'll use modules and records to implement the model and we'll also use advanced meta-programming features for constructing LINQ queries. If you want to use F# for creating an MVC application, you have a few options. It should be possible to create the web application solely as an F# project. However, we'll use a more convenient approach. We'll create a standard C# MVC project and move all the actual implementation to an F# library. We'll look at the application structure shortly. The following screenshot shows a page that lists products in the Northwind database: Sun, 09 May 2024 20:43:52 +0200 e23a985d-1cb1-4f49-8343-a9c6d6e59d74 http://netstudent.cz/Articles/wcf-pro-zacatecniky-6-dil-mereni-udaju-pomoci-performance-counters Kryštof Laryš WCF pro začátečníky – 6. díl: měření údajů pomocí Performance Counters Performance countery nám slouží k měření spousty údajů týkajících se služby, endpointů či kontraktů. Sun, 21 Mar 2025 00:00:00 +0100 0070a651-6c94-447a-8e0a-8fbd59b480e0 http://netstudent.cz/Articles/wcf-pro-zacatecniky-5-dil-osetreni-chyb-na-strane-sluzby-pomoci-faultcontract Kryštof Laryš WCF pro začátečníky – 5. díl: ošetření chyb na straně služby pomocí FaultContract V dnešním díle vám ukážu dva z postupů, jak docílit toho, aby služba jednoduše ošetřila výjimku, která nastane, a zprávu s chybou následně odeslala klientské aplikaci. K tomu slouží FaultContract atribut. Sat, 20 Mar 2025 00:00:00 +0100 ccb61726-144d-4ca0-809c-8152220da717 http://tomasp.net/blog/excerpt-gui-workflows.aspx Tomáš Petříček Programming user interfaces using F# workflows Numerous Manning partners already published several exceprts from my Real-World Functional Programming book. You can find a list on the book's web page. However, the last excerpt published at DotNetSlackers is particularly interesting. It discusses how to use F# asynchronous workflows to write GUI applications. This is a very powerful programming pattern that is very difficult to do in any other .NET language. We first discussed it with Don Syme during my internship at Microsoft Research and I found it very elegant, so I made some space for it in the book. In fact, the entire Chapter 16 discusses various reactive programming techniques that can be used in F#. When designing applications that don't react to external events, you have lots of control flow constructs available, such as if-then-else expressions, for loops and while loops in imperative languages, or recursion and higher-order functions in functional languages. Constructs like this make it easy to describe what the application does. The control flow is clearly visible in the source code, so drawing a flowchart to describe it is straightforward. Understanding reactive applications is much more difficult. A typical C# application or GUI control that needs to react to multiple events usually involves mutable state. When an event occurs, it updates the state and may run more code in response to the event, depending on the current state. This architecture makes it quite difficult to understand the potential states of the application and the transitions between them. Using asynchronous workflows, we can write the code in a way that makes the control flow of the application visible even for reactive applications. You can read the complete article here: Programming user interfaces using F# workflows [^]. It is also worth adding that Manning offers 30% discount to DotNetSlackers readers (see the article for details!) Thu, 18 Feb 2025 00:25:51 +0100 f49b45a4-9533-4cf8-b886-d42ac2682191 http://tomasp.net/blog/custom-linq-grouping.aspx Tomáš Petříček Using custom grouping operators in LINQ You can use LINQ to write queries that perform grouping of data using group by or ordering of data using orderby clause. LINQ provides the default (and the most common) implementation of both of the operations, but sometimes you may need a slightly different behavior when grouping or ordering data (this article is motivated by a question on StackOverflow which needs to do exactly that for grouping). Let's look at a simple example, which shows when we may need a different behavior when grouping data. For example, we may have the following list of stock trades containing a name of a stock and the price of the trade (stored for example as a list of TradeInfo classes with properties Name and Price): { { Name = "MSFT", Price = 80.00 }, { Name = "MSFT", Price = 70.00 }, { Name = "GOOG", Price = 100.00 }, { Name = "GOOG", Price = 200.00 }, { Name = "GOOG", Price = 300.00 }, { Name = "MSFT", Price = 30.00 }, { Name = "MSFT", Price = 20.00 } }Now, we may want to group adjacent trades into a single summary record which will contain the name of the stock (which is same for all trades in each group), the number of trades in the group and an average price in the group. The desired results are: { { Name = "MSFT", Count = 2, AvgPrice = 75.00 }, { Name = "GOOG", Count = 3, AvgPrice = 200.00 }, { Name = "MSFT", Count = 2, AvgPrice = 25.00 } }The operation that we want to do is very similar to group by in LINQ, but it doesn't do quite the same thing! If we used group by, we would get only two groups as the result. However, as I wrote earlier, we want to group only adjacent trades. You could write your own extension method to do this, but then you need to leave the elegant LINQ query syntax. In this article, I'll show you how to get the desired results using a simple LINQ query with a group by clause... Sun, 07 Feb 2025 20:13:32 +0100 a69ec198-4a2d-4c25-a755-7863fb34ce05 http://tomasp.net/blog/book-deal.aspx Tomáš Petříček Deal of the day: Real-World Functional Programming Some time ago, I received my copies of Real-World Functional Programming. I started working on it back in May 2008 and as many people who had more experience with writing books told me, it took longer than I was expecting! Anyway, I have to say, it was worth it, holding the actual printed book with my name on the cover is just fantastic! The goal of the book is to present functional programming concepts and ideas in a readable form. I wanted to create a book that will teach you how to think functionally without using the usual shock therapy that people usually feel when seeing functional programming for the first time. There are already a couple of reviews that suggest I was quite successful: Functional Programming for the Real World, by Tomas Petricek and Jon Skeet, has been a very helpful book for moving to F# from C#, as the authors do a fantastic job of helping to explain the differences between OOP and FP. James Black at Amazon.com This book isn’t just a simple introduction to programming in F#; it’s an introductory text on functional programming covering the many reasons why it is time for this programming paradigm to finally be accepted by mainstream programmers. And it also contains much more... CliveT, Software Engineer at Red Gate Software ... and there are many other great comments about the book at Manning book page. Deal of the day (January 24) Finally, here is one great news if you're interested in getting the book! Real-World Functional Programming is Manning's Deal of the Day this Sunday, January 24. On this day, the print book is available for $20 from the Manning website, with code dotd0124. Sun, 24 Jan 2025 17:00:41 +0100 2c859752-d930-4706-a330-29b4b8c0c452 http://tomasp.net/blog/accelerator-quotations.aspx Tomáš Petříček Accelerator and F# (IV.): Composing computations with quotations In this article series, we're talking about the Accelerator project and I'm presenting an F# library that I implemented, which allows you to use Accelerator [references] in a more sophisticated way. We've seen two examples of using Accelerator directly (see also introduction and Game of Life). In the previous article I introduced my F# library for working with Accelerator. We've seen F# functions from the DataParallel module, we implemented an algorithm that rotates an image using these functions and finally, we've seen that we can take this ordinary F# code and run it using Accelerator. This is all possible thanks to F# quotations, which we can use to get an AST (a source code) of an F# function we wrote (if the function is marked in some special way). In this part of the series, we're going to look at working with quotations explicitly. We'll use meta-programming techniques to work with Accelerator. Meta-programming means writing programs that manipulate with other programs or pieces of code. This is exactly what we're going to do in this article. We'll write an F# function (running on CPU) that builds a program, which we'll then run using Accelerator. This is quite interesting approach, which isn't possible when we call Accelerator methods as standard F# functions or .NET methods. The benefit is that we'll clearly see which parts of program run on CPU and what parts execute on GPU or using X64 multi-core target. We could also perform more complicated optimizations with the code (because this wouldn't affect the readability). Just for your reference, here is the list of articles in this series in case you missed some of them: Accelerator and F# (I.): Introduction and calculating PI Accelerator and F# (II.): The Game of Life on GPU Accelerator and F# (III.): Data-parallel programs using F# quotations Accelerator and F# (IV.): Composing computations with quotations However, enough with theory and let's take a look at some code samples! This time, we'll implement blurring of an image (also called convolution). Another example how to write this in F# using Accelerator is Satnam Singh's blog post [4]. Our example will be different, because we'll write the code as standard F# program and then have it translated to Accelerator automatically using quotations. We'll also talk about the architecture of the library that we're using and look at some performance results. Tue, 12 Jan 2025 03:20:36 +0100 848e1641-c34a-440d-ba2b-d519e5c8115b http://tomasp.net/blog/accelerator-dataparallel.aspx Tomáš Petříček Accelerator and F# (III.): Data-parallel programs using F# quotations If you've been following this article series, you already know that Accelerator is a MSR library [1, 2] that allows you to run code in parallel on either multi-core CPU or using shaders on GPU (see introduction). We also discussed a direct way to use Accelerator from F# (by calling Accelerator methods directly) and implemented Conway's Game of Life. In this article, we'll look at more sophisticated way of using Accelerator from F#. We'll introduce F# quotations and look at translating 'normal' F# code to use Accelerator. In general, F# quotations allow us to treat F# code as data structure and manipulate with it. This is very similar to C# expression trees, but the F# implementation is more powerful. We can also mark a standard method or a function with a special attribute that tells the compiler to store quotation of the body. Then we can access the quotation and traverse it or modify it. In this article we'll use a function that takes an F# quotation (containing a limited set of functions) and executes it using MSR Accelerator. Implementing this functionality is a bit complicated, so we won't discuss the implementation now. We'll leave this for some future article of this series. In future, we'll also look at other interesting possibilities that we have when writing code using quotations. Here is a list of articles in this series and of the articles that I'm planning to add: Accelerator and F# (I.): Introduction and calculating PI Accelerator and F# (II.): The Game of Life on GPU Accelerator and F# (III.): Data-parallel programs using F# quotations Accelerator and F# (IV.): Composing computations with quotations Mon, 04 Jan 2025 12:50:13 +0100 d8518db4-b7c5-4db9-948b-c7adfe799c29 http://tomasp.net/blog/accelerator-life-game.aspx Tomáš Petříček Accelerator and F# (II.): The Game of Life on GPU In the previous article, I introduced the Microsoft Research Accelerator library. It allows us to write computations with arrays in C# and execute them in parallel on multi-core CPU or more interestingly, using GPU shaders. In the previous artcile, we've seen how Accelerator works and how it can be accessed from F#. In this article, we'll look at one more interesting F# demo - we'll implement the famous Conway's Game of Life [1] using Accelerator. We'll use a v2 version of Accelerator which has been announced just recently and is available from Microsoft Connect [2]. This article is the second one from a series about using Accelerator from F#. Today, we'll use Accelerator types directly from F# - this is the simplest possible approach and is very similar to the way you'd work with Accelerator in C#. However, we can use some nice F# features such as custom operators to make the code more readable. In the next article, we'll discuss a different approach - we'll look how to execute more "standard" F# code (that doesn't reference Accelerator explicitly) with Accelerator using F# quotations. The list of articles may change, but here is a list of articles that I'm currently planning to write: Accelerator and F# (I.): Introduction and calculating PI Accelerator and F# (II.): The Game of Life on GPU Accelerator and F# (III.): Data-parallel programs using F# quotations Accelerator and F# (IV.): Composing computations with quotations Mon, 28 Dec 2024 21:16:03 +0100 92ab6ec2-f92b-4be6-992d-db254e385ce2 http://tomasp.net/blog/accelerator-intro.aspx Tomáš Petříček Accelerator and F# (I.): Introduction and calculating PI I already wrote about two projects that I worked on during an internship at MSR back in 2007 (ASP.NET support in F# and F# WebTools). Even though this was more than 2 years ago (and I did one more internship at MSR in the meantime), I still have one more project that I never published on the web. The folks from the F# team reminded me of this project recently, so I thought I could finally publish it. The project used Microsoft Research Accelerator [1, 2], which is a C# library for developing array-based computations and executing them on a GPU. More recently, the Accelerator team at MSR published Accelerator v2 [3], which was a good motivation to update my original project... In this article, we'll look at the simplest way of using Accelerator from F#. Accelerator provides a managed interface that can be naturally used from both C# and F#. We can use a mix of method calls and overloaded operators to describe a computation. In F#, we'll also define our additional custom operators to make the code a bit nicer. After we introduce Accelerator using a simple C# demo, we'll look how to calculate an approximate value of the PI number using a Monte-Carlo method. This article is the first one from a series about using Accelerator from F#. The list of articles may change, but here is a list of articles that I'm currently planning to write: Accelerator and F# (I.): Introduction and calculating PI Accelerator and F# (II.): The Game of Life on GPU Accelerator and F# (III.): Data-parallel programs using F# quotations Accelerator and F# (IV.): Composing computations with quotations Mon, 21 Dec 2024 03:21:03 +0100 cf2374a1-6957-4ee7-aa4c-06a98186d759 http://tomasp.net/blog/book-completed.aspx Tomáš Petříček Real-World Functional Programming: Completed and printed! If you're following my blog or if you're interested in F# or functional programming in .NET, you probably noticed that I was working on a book Real-World Functional Programming. At some point, we called it Functional Programming for the Real-World, but then we changed the title back to a better sounding version Real-World Functional Programming (subtitle With examples in F# and C#). The book is also reason for a lower number of blog posts over the last year. Over the last month or so, we were doing the final edits, reviewing the final PDF version (I fixed quite a lot minor issues, synchronized book with the Beta 2 F# release and so on). Anyway, before a few days, I received the following email (as an author, I receive the same emails as those who ordered the book through the Manning Early Access Program, so that I can see what we're sending to our dear readers): Dear Tomas Petricek, We are pleased to announce that Real-World Functional Programming is now complete! As a MEAP subscriber you can download your copy of the finished ebook right now! (...) This ebook is the final version, identical to the softbound edition, which is currently being printed and will be available on December 24. If you chose the printed book option when you originally subscribed, we'll ship it to you automatically—no action required from you. Finally finished! Yes, that's right. The book is finally completed and as far as I know, it has been printed last week! If you already ordered the book, you won't receive it before Christmas, but it should come shortly after. I can't wait to see the book actually printed. The transition from the Word drafts I initially wrote to a final PDF version was already felt fantastic and I thought "It looks like a real book!" Among other things, there are now graphical arrows with comments inside listings, which looks really great and makes code listings much easier to read. Now I can look forward to seeing the actual book. Maybe I'm too conservative, but I have to say that I'm really glad that I wrote the book before everything is going to be published just electronically! Here is a couple of links that you may found interesting if you want to look inside the book... Sat, 19 Dec 2024 21:54:28 +0100 7350acae-9a14-487a-95af-c628ace6d941 http://www.vbnet.cz/clanek--136-slozitejsi_konstrukty_low_level_pristup_a_genericke_programovani.aspx Jakub Čermák Složitější konstrukty, low-level přístup a generické programování V tomto článku je popsána nadstavba C++ pro práci s .NET prostředím zvaná C++/CLI umožňující vytvářed mixed assembly obsahující jak managed tak unmanaged kód. V tomto díle jsou popsány pokročilejší partie jazyka týkající se hlavně objektů, low-level přístupu k managed objektům a generického programování.[Zobrazit článek] Mon, 14 Sep 2024 00:00:00 +0200 b3a506b3-7a69-4087-aab1-69b3eb47ddbf http://www.vbnet.cz/clanek--135-uvod_do_jazyka_a_zakladni_konstrukce.aspx Jakub Čermák Úvod do jazyka a základní konstrukce V tomto článku je popsána nadstavba C++ pro práci s .NET prostředím zvaná C++/CLI umožňující vytvářed mixed assembly obsahující jak managed tak unmanaged kód. V prvním díle je popsána myšlenka jazyka a základní syntaktické konstrukty (základní typy, podmínky, cykly, pole, namespace a část tříd a objektů). U čtenáře je předpokládána znalost .NET frameworku a nativního programování nejlépe v C++ (alespoň syntaxi a základy).[Zobrazit článek] Thu, 03 Sep 2024 00:00:00 +0200 f0bed978-ff38-457c-857b-bc5936002142 http://tomasp.net/blog/functional-excerpts-and-discount.aspx Tomáš Petříček Functional Programming: Available Chapter Excerpts & Discount The work on my book Functional Programming for the Real World is slowly getting to the end. I'm currently creating index for the last couple of chapters and doing final updates based on the feedback from reviews and also from the forum at manning.com (this means that if you have some suggestions, it's the best time to post them - I haven't yet replied to all of them, but I'll certainly do that before the manuscript will go to the production). Sun, 26 Jul 2024 03:41:14 +0200 4e08d0af-d649-4980-8fea-349a91dd76f2 http://tomasp.net/blog/fsharp-webcast-objects.aspx Tomáš Petříček F# Webcast (IV.) - Developing standard .NET libraries In the previous parts of this webcast series we've developed an F# script that downloads RSS feeds asynchronously and in parallel and searches them for the specified keywords. We followed the usual F# development style, so after introducing the basic functional concepts, we wrote the code in the simples possible style and demonstrated how to use System.Xml and System.Net namespaces. Then we refactored the existing code, to run asynchronously and process the results potentially in parallel, which was very easy thanks to F# asynchronous workflows. In this part of the series, we'll make the next evolutionary step of our sample application. We'll turn the code that originally used F# tuples and lists into code that uses standard .NET objects and we'll also see how to declare a class in F#. This simple modification will turn the script into an F# library that is almost indistinguishable from a library developed in C#. We'll also look how you can use the library from C# web application to show the interop between C# and F# in practice. We'll start with the code from the previous part, so if you missed that, you may want to check it out or download the source code. Mon, 15 Jun 2024 20:09:04 +0200 558c17c5-ea64-4c4e-89f3-8203057300ae http://tomasp.net/blog/fsharp-webcast-async.aspx Tomáš Petříček F# Webcast (III.) - Using Asynchronous Workflows In this webcast, we'll look at improving the code for downloading and processing RSS feeds that I presented in the second part (if you didn't see earlier parts, the first one was an introduction to basic functional ideas). The previous part demonstrated how to use .NET libraries and we implemented a simple downloadUrl function for obtaining content of from the web and we've also seen how to load the data into an XML document object and how to filter items. In this part, we'll modify the code to run asynchronously and potentially in parallel. To use some of the functionality, you'll need to get FSharp.PowerPack.dll, which is available with the VS 2008 installation or as a separated download for VS 2010 [4]. Now that we have the first version of the code, we can start refactoring it. I'm using the term in a slightly vague meaning - we're of course going to change the behavior of the code. We'll wrap it into F# asynchronous workflow to run without blocking threads and we'll also run multiple downloads in parallel. However, this can still be viewed as refactoring in some sense, because we're not changing the core behavior of the code. As you can see from the webcast, these kinds of refactorings are also very nicely supported by F# syntax... Fri, 05 Jun 2024 03:39:39 +0200 219429b1-2634-4795-88b9-2c2912af4edf http://tomasp.net/blog/fsharp-webcast-dotnet.aspx Tomáš Petříček F# Webcast (II.) - Using .NET libraries About a week ago I posted the first part of my F# webcast series. It focused on explainining the basic ideas behind functional programming such as immutability, recursion and passing functions as arguments to other functions (or methods in C#). In the first part, we've seen some C# code to demonstrate the ideas and also a bit of F#, mainly to show the basic language features. The second part is going to be exclusively about F#. It'll demonstrate how we can start writing a demo application that grabs data from RSS feeds and processes them. You'll learn how to access .NET libraries from F# (in particular, we'll use System.Net and System.Xml). We'll develop the code iteratively, which means that we'll start by simply enumerating the RSS elements using for loop and printing the results and then we'll refactor the code to use tuples and sequence expressions to turn it into processing code that generates a sequence of feed items. Finally we'll also demonstrate how to use some of the functions from the previous part such as List.filter in practice. Mon, 01 Jun 2024 14:57:53 +0200 21a5f62a-ecca-4ea4-a26a-e4d72a38cc56 http://tomasp.net/blog/fsharp-webcast-functional.aspx Tomáš Petříček F# Webcast (I.) - Introducing functional concepts Now that Visual Studio 2010 Beta 1 is out, it is finally a good time to take a look at one of the (in my opinion) most interesting new features in the new release - the F# language. F# existed for quite a long time now as Microsoft Research project, but is now becoming a real Microsoft product. Interestingly, F# is still available as a plugin for Visual Studio 2008, so if you want to try it you don't have to install the whole new beta of 2010. There are already many resources for learning F# including my functional programming overview, which is a Manning Greenpaper for the book Functional Programming for the Real World that I'm writing with Jon Skeet and my four-part F# introduction. There are also some useful links on the official F# web site including some talk recordings. However, I haven't yet seen any good F# webcast focusing mainly on showing F# source code, starting from simple functional concepts to the real-world features like asynchronous workflows and object-oriented programming in F#, so I decided to create one. So, here it is... Mon, 25 May 2024 13:39:54 +0200 e808cc29-53d5-430b-9d0f-3fcb17a11eac http://tomasp.net/blog/internship-match-bang.aspx Tomáš Petříček Internship project: Reactive pattern matching I already mentioned that I was doing my second internship with Don Syme at Microsoft Research in Cambridge. This time, I was in Cambridge for 6 months from October until April, so it has been more than a month since I left, but as you can guess I didn't have time to write anything about the internship until now... There isn't much to say though, because the internship was simply fantastic. Cambridge is a beautiful place (here are some autumn and winter photos), the Microsoft Research lab in Cambridge is full of smart people, so it is a perferct working environment (except that you realize that you're not as clever as you think :-)). Also, it is just a few meters away from the Computer Laboratory of the Cambridge University, so there are always many interesting talks and seminars. So, big thanks to Don Syme, James Margetson and everyone else who I had a chance to work with during the internship. One of the reasons why I didn't have much time to write about the internship earlier is that I was invited to the Lang.NET Symposium shortly after the end of the internship. I had a chance to talk about my project there as well and there is even a video recording from the talk (the link is below), so you can watch it to find out more about my recent F# work. Sun, 17 May 2024 23:00:28 +0200 df1a3a40-d938-4f4d-b32f-1954280a9b11 http://tomasp.net/blog/imperative-ii-break.aspx Tomáš Petříček Imperative computation in F# (II.) - Writing break and continue As I already wrote in the first part of this series, the F# language doesn't support some of the language constructs known from imperative languages such as C#. In particular, we cannot use imperative return statement that returns the result of a function from any place in the function code. In functional languages, every construct is an expression, so to get the overall result of the function, the F# language evaluates the expression and the value of the expression is used as the result. In the previous article, we've seen that we can simulate this construct in the F# language using F# computation expressions and I showed how to implement computation named imperative that allows us to write for example the exists function for working with sequences like this: let exists f inp = imperative { for v in inp do if f(v) then return true return false } In this article, we're going to look at two more imperative constructs and we're going to talk about break and continue. We'll see that we can quite easily extend the computation builder from the previous article to allow writing code that is syntactically very close to what you would write in C#. As I already mentioned, there are of course some performance overheads when using computation expressions, but I find it very interesting how nice imperative syntax we can get in functional F#: imperative { for x in 1 .. 10 do if (x % 3 = 0) then do! continue printfn "number = %d" x } The only difference between this code and the code we'd probably write if F# supported continue as a keyword is that we need to wrap the code inside the imperative computation and that we need to add the do! primitive before the continue value. Now that we've seen an example of using the continue value inside the imperative computations, let's look how we can extend the computation builder from the previous article to add this feature... Sat, 25 Apr 2024 16:31:15 +0200 89feef15-4d25-4140-8ca4-ae2bb48b655f http://tomasp.net/blog/imperative-i-return.aspx Tomáš Petříček Imperative computation in F# (I.) - Returning results from a function One of the limitations of F# is that it doesn't very well support some of the advanced imperative language constructs such as break, continue or imperative style of returning value from a function, meaning that you can't write something like return false in the middle of the function. This has good reasons. F# doesn't in principle have the notion of currently executing statement and instead treat every code you write as an expression. Clearly, when there is no current statement, we cannot jump to other statements. If you're looking for more information about these basic principles, you can take a look at my book Real World Functional Programming, which covers this distinction in details in chapter 2, but we'll look at a brief example that will clarify this idea shortly. Often, there is really no need to use break or other imperative constructs in F#, because you can write the same thing more elegantly using one of the provided higher order function such as Seq.exists or Seq.tryfind. However, there are still some cases where the imperative programming style makes it easier to express our original intention. Also, implementing your own higher order functions (akin to Seq.exists) would sometimes be much easier if we could just use imperative return. So, what can be done about this? Thu, 19 Mar 2025 02:05:03 +0100