From 186d5364dc9366ff95ac50f47781093a490137d9 Mon Sep 17 00:00:00 2001
From: "Yann Esposito (Yogsototh)"
allPoints
is a pure list.
Therefore, calling allPoints
will always render the same result and Haskell is clever enough to use this property.
-While Haskell doesn’t garbage collect allPoints
the result is reused for free.
+While Haskell doesn’t garbage collect allPoints
the result is reused for free.
We did not specified this value should be saved for later use.
It is saved for us.
@@ -631,7 +631,7 @@ instead of using a 3D projection of quaternions.
I am pretty sure this construction is not useful for numbers.
But it will be enough for us to create something that look nice.
-This section is quite long, but don’t be afraid, +
This section is quite long, but don’t be afraid, most of the code is some OpenGL boilerplate. If you just want to skim this section, here is a high level representation:
@@ -647,7 +647,7 @@ here is a high level representation:Drawing:
We have finished with the OpenGL section, let’s talk about how we +
We have finished with the OpenGL section, let’s talk about how we generate the 3D points and colors. First, we will set the number of details to 200 pixels in the three dimensions.
@@ -1017,7 +1017,7 @@ depthPoints = doIf you prefer the first version, then just imagine how hard it will be to change the enumeration of the point from (x,y) to (x,z) for example.
-Also, we didn’t searched for negative values. +
Also, we didn’t searched for negative values.
This modified Mandelbrot is no more symmetric relatively to the plan y=0
.
But it is symmetric relatively to the plan z=0
.
Then I mirror these values.
This code is cleaner but many things doesn’t feel right. +
This code is cleaner but many things doesn’t feel right. First, all the user interaction code is outside our main file. I feel it is okay to hide the detail for the rendering. But I would have preferred to control the user actions.
@@ -1276,12 +1276,12 @@ We will have two choices:Our main problem come from user interaction. -If you ask “the Internet”, +If you ask “the Internet”, about how to deal with user interaction with a functional paradigm, the main answer is to use functional reactive programming (FRP). -I won’t use FRP in this article. -Instead, I’ll use a simpler while less effective way to deal with user interaction. -But The method I’ll use will be as pure and functional as possible.
+I won’t use FRP in this article. +Instead, I’ll use a simpler while less effective way to deal with user interaction. +But The method I’ll use will be as pure and functional as possible.Here is a real working code, I’ve hidden most display functions. +
Here is a real working code, I’ve hidden most display functions. The YGL, is a kind of framework to display 3D functions. But it can easily be extended to many kind of representation.
@@ -1523,7 +1523,7 @@ idleAction tnew world = world {Now the function which will generate points in 3D.
The first parameter (res
) is the resolution of the vertex generation.
More precisely, res
is distance between two points on one direction.
-We need it to “close” our shape.
The type Function3D
is Point -> Point -> Maybe Point
.
Because we consider partial functions
@@ -1592,7 +1592,7 @@ ymandel x y z = fromIntegral (mandel x y z 64) / 64
-
I won’t explain how the magic occurs here. +
I won’t explain how the magic occurs here.
If you are interested, just read the file YGL.hs
.
It is commented a lot.
Our code architecture feel very clean.
All the meaningful code is in our main file and all display details are
externalized.
-If you read the code of YGL.hs
, you’ll see I didn’t made everything perfect.
-For example, I didn’t finished the code of the lights.
+If you read the code of YGL.hs
, you’ll see I didn’t made everything perfect.
+For example, I didn’t finished the code of the lights.
But I believe it is a good first step and it will be easy to go further.
Unfortunately the program of the preceding session is extremely slow.
We compute the Mandelbulb for each frame now.
As we can use imperative style in a functional language, know you can use functional style in imperative languages. This article exposed a way to organize some code in a functional way. -I’d like to stress the usage of Haskell made it very simple to achieve this.
+I’d like to stress the usage of Haskell made it very simple to achieve this.Once you are used to pure functional style, it is hard not to see all advantages it offers.
The code in the two last sections is completely pure and functional.
-Furthermore I don’t use GLfloat
, Color3
or any other OpenGL type.
+Furthermore I don’t use GLfloat
, Color3
or any other OpenGL type.
If I want to use another library in the future,
I would be able to keep all the pure code and simply update the YGL module.
The YGL
module can be seen as a “wrapper” around 3D display and user interaction.
+
The YGL
module can be seen as a “wrapper” around 3D display and user interaction.
It is a clean separator between the imperative paradigm and functional paradigm.
If you want to go further, it shouldn’t be hard to add parallelism. +
If you want to go further, it shouldn’t be hard to add parallelism. This should be easy mainly because most of the visible code is pure. Such an optimization would have been harder by using directly the OpenGL library.
@@ -1920,7 +1920,7 @@ O(n².log(n)) to O(n³).Unfortunately, I couldn’t make this program to work on my Mac. More precisely, I couldn’t make the DevIL library work on Mac to output the image. Yes I have done a brew install libdevil
. But even a minimal program who simply write some jpg
didn’t worked. I tried both with Haskell
and C
.↩
Unfortunately, I couldn’t make this program to work on my Mac. More precisely, I couldn’t make the DevIL library work on Mac to output the image. Yes I have done a brew install libdevil
. But even a minimal program who simply write some jpg
didn’t worked. I tried both with Haskell
and C
.↩
Generally in Haskell you need to declare a lot of import lines.
diff --git a/output/Scratch/en/blog/feed/feed.xml b/output/Scratch/en/blog/feed/feed.xml
index deb2e5d38..c66569ccf 100644
--- a/output/Scratch/en/blog/feed/feed.xml
+++ b/output/Scratch/en/blog/feed/feed.xml
@@ -104,7 +104,7 @@ Imperative language could also benefit from this functional organization.</p&
<div class="intro">
-<p><span class="sc"><abbr title="Too long; didn't read">tl;dr</abbr>: </span> Web typography sucks and we’ll have to wait forever before it will be fixed.</p>
+<p><span class="sc"><abbr title="Too long; didn't read">tl;dr</abbr>: </span> Web typography sucks and we’ll have to wait forever before it will be fixed.</p>
</div>
@@ -141,7 +141,7 @@ We can all create better web typography ourselves, today.»</p>
<p><span class="sc"><abbr title="Too long; didn't read">tl;dr</abbr>: </span> A simple yesod tutorial.
Yesod is a Haskell web framework.
-You shouldn’t need to know Haskell. </p>
+You shouldn’t need to know Haskell. </p>
<blockquote>
<center><span class="sc"><b>Table of content</b></span></center>
@@ -203,8 +203,7 @@ Then some believed it would be a good idea to invent many <span class="sc">
<p><span class="sc"><abbr title="Too long; didn't read">tl;dr</abbr>: </span></p>
-<p><a href="http://www.yesodweb.com">Yesod</a> is a web framework which recently reached the maturity for which you should consider to use it.
-Before telling you why you should learn Haskell and use yesod, I will talk about ideas yesod introduced and I didn’t saw in other frameworks before.</p>
+<p><a href="http://www.yesodweb.com">Yesod</a> is a framework which has recently matured to the point where you should consider using it. Before telling you why you should learn Haskell and use Yesod, I will illustrate the many features Yesod introduces which are missing in other frameworks.</p>
</div>
@@ -212,11 +211,11 @@ Before telling you why you should learn Haskell and use yesod, I will talk about
<h2 id="type-safety">Type safety</h2>
-<p>Let’s start by an obligatory link from <a href="http://xkcd.com">xkcd</a>:</p>
+<p>Let’s start by an obligatory link from <a href="http://xkcd.com">xkcd</a>:</p>
<img src="http://imgs.xkcd.com/comics/exploits_of_a_mom.png" alt="SQL injection by a mom" />
-<p>When you create a web application, a lot of time is spent dealing with ...</p></img></img>
+<p>When you create a web application, a lot of time is spent dealing with strin...</p></img></img>
tlàl : Un exemple progressif d’utilisation d’Haskell.
+ tlàl : Un exemple progressif d’utilisation d’Haskell.
Vous pourrez voir un ensemble de Mandelbrot étendu à la troisième dimension.
De plus le code sera très propre.
Les détails de rendu sont séparés dans un module externe.
@@ -72,7 +72,7 @@ Vous pouvez vous inspirer de ce code utilisant le paradigme fonctional dans tous
This section is quite long, but don’t be afraid,
+ This section is quite long, but don’t be afraid,
most of the code is some OpenGL boilerplate.
If you just want to skim this section,
here is a high level representation: Drawing: We have finished with the OpenGL section, let’s talk about how we
+ We have finished with the OpenGL section, let’s talk about how we
generate the 3D points and colors.
First, we will set the number of details to 200 pixels in the three dimensions. If you prefer the first version, then just imagine how hard it will be to change the enumeration of the point from (x,y) to (x,z) for example. Also, we didn’t searched for negative values.
+ Also, we didn’t searched for negative values.
This modified Mandelbrot is no more symmetric relatively to the plan This code is cleaner but many things doesn’t feel right.
+ This code is cleaner but many things doesn’t feel right.
First, all the user interaction code is outside our main file.
I feel it is okay to hide the detail for the rendering.
But I would have preferred to control the user actions. Our main problem come from user interaction.
-If you ask “the Internet”,
+If you ask “the Internet”,
about how to deal with user interaction with a functional paradigm,
the main answer is to use functional reactive programming (FRP).
-I won’t use FRP in this article.
-Instead, I’ll use a simpler while less effective way to deal with user interaction.
-But The method I’ll use will be as pure and functional as possible. Here is a real working code, I’ve hidden most display functions.
+ Here is a real working code, I’ve hidden most display functions.
The YGL, is a kind of framework to display 3D functions.
But it can easily be extended to many kind of representation. Now the function which will generate points in 3D.
The first parameter ( The type I won’t explain how the magic occurs here.
+ I won’t explain how the magic occurs here.
If you are interested, just read the file
-Let’s play the song of our people
+Let’s play the song of our people
allPoints
is a pure list.
Therefore, calling allPoints
will always render the same result and Haskell is clever enough to use this property.
-While Haskell doesn’t garbage collect allPoints
the result is reused for free.
+While Haskell doesn’t garbage collect allPoints
the result is reused for free.
We did not specified this value should be saved for later use.
It is saved for us.
@@ -631,7 +631,7 @@ instead of using a 3D projection of quaternions.
I am pretty sure this construction is not useful for numbers.
But it will be enough for us to create something that look nice.
-
-
@@ -903,7 +903,7 @@ Mainly there are two parts: apply some transformations, draw the object.
The 3D Mandelbrot
-y=0
.
But it is symmetric relatively to the plan z=0
.
Then I mirror these values. res
) is the resolution of the vertex generation.
More precisely, res
is distance between two points on one direction.
-We need it to “close” our shape.Function3D
is Point -> Point -> Maybe Point
.
Because we consider partial functions
@@ -1592,7 +1592,7 @@ ymandel x y z = fromIntegral (mandel x y z 64) / 64
YGL.hs
.
It is commented a lot.
Our code architecture feel very clean.
All the meaningful code is in our main file and all display details are
externalized.
-If you read the code of YGL.hs
, you’ll see I didn’t made everything perfect.
-For example, I didn’t finished the code of the lights.
+If you read the code of YGL.hs
, you’ll see I didn’t made everything perfect.
+For example, I didn’t finished the code of the lights.
But I believe it is a good first step and it will be easy to go further.
Unfortunately the program of the preceding session is extremely slow.
We compute the Mandelbulb for each frame now.
As we can use imperative style in a functional language, know you can use functional style in imperative languages. This article exposed a way to organize some code in a functional way. -I’d like to stress the usage of Haskell made it very simple to achieve this.
+I’d like to stress the usage of Haskell made it very simple to achieve this.Once you are used to pure functional style, it is hard not to see all advantages it offers.
The code in the two last sections is completely pure and functional.
-Furthermore I don’t use GLfloat
, Color3
or any other OpenGL type.
+Furthermore I don’t use GLfloat
, Color3
or any other OpenGL type.
If I want to use another library in the future,
I would be able to keep all the pure code and simply update the YGL module.
The YGL
module can be seen as a “wrapper” around 3D display and user interaction.
+
The YGL
module can be seen as a “wrapper” around 3D display and user interaction.
It is a clean separator between the imperative paradigm and functional paradigm.
If you want to go further, it shouldn’t be hard to add parallelism. +
If you want to go further, it shouldn’t be hard to add parallelism. This should be easy mainly because most of the visible code is pure. Such an optimization would have been harder by using directly the OpenGL library.
@@ -1920,7 +1920,7 @@ O(n².log(n)) to O(n³).Unfortunately, I couldn’t make this program to work on my Mac. More precisely, I couldn’t make the DevIL library work on Mac to output the image. Yes I have done a brew install libdevil
. But even a minimal program who simply write some jpg
didn’t worked. I tried both with Haskell
and C
.↩
Unfortunately, I couldn’t make this program to work on my Mac. More precisely, I couldn’t make the DevIL library work on Mac to output the image. Yes I have done a brew install libdevil
. But even a minimal program who simply write some jpg
didn’t worked. I tried both with Haskell
and C
.↩
Generally in Haskell you need to declare a lot of import lines.
diff --git a/output/Scratch/fr/blog/feed/feed.xml b/output/Scratch/fr/blog/feed/feed.xml
index a5181c6c2..92178b15b 100644
--- a/output/Scratch/fr/blog/feed/feed.xml
+++ b/output/Scratch/fr/blog/feed/feed.xml
@@ -52,7 +52,7 @@ just continue to read as a standard web page.
<div class="intro">
-<p><span class="sc"><abbr title="Trop long à lire">tlàl</abbr> : </span> Un exemple progressif d’utilisation d’Haskell.
+<p><span class="sc"><abbr title="Trop long à lire">tlàl</abbr> : </span> Un exemple progressif d’utilisation d’Haskell.
Vous pourrez voir un ensemble de Mandelbrot étendu à la troisième dimension.
De plus le code sera très propre.
Les détails de rendu sont séparés dans un module externe.
@@ -117,7 +117,7 @@ We can all create better web typography ourselves, today.»</p>
<p>ou en français :</p>
<blockquote>
- <p>«Nous ne somme pas obligé d’attendre le développement des navigateurs.
+ <p>«Nous ne somme pas obligé d’attendre le développement des navigateurs.
Nous pouvons crÃ...</p></blockquote></img>