Record of experiments, readings, links, videos and other things that I find on the long road.
Registro de experimentos, lecturas, links, vídeos y otras cosas que voy encontrando en el largo camino.
Showing posts with label Haskell. Show all posts
Showing posts with label Haskell. Show all posts
Sunday, November 26, 2017
Interesting Talk: "Side Effects are a Public API"
I've just watched this very interesting talk by Christopher Armstrong
Sunday, November 23, 2014
Saturday, November 22, 2014
Thursday, November 13, 2014
Wednesday, November 12, 2014
Euler Project: Problem 2 in Haskell
This is my solution in Haskell to the second problem:
I still get a bit dizzy when I think about the second solution...
You will find a great explanation of the second solution in this post:
Fibonacci numbers: the slow way or the fast and lazy way
You'll find the solutions in Haskell to Project Euler problems that I've done so far in this GitHub repository.
I still get a bit dizzy when I think about the second solution...
You will find a great explanation of the second solution in this post:
Fibonacci numbers: the slow way or the fast and lazy way
You'll find the solutions in Haskell to Project Euler problems that I've done so far in this GitHub repository.
Thursday, November 6, 2014
Euler Project: Problem 1 in Haskell
This is my solution in Haskell to the first problem:
I used a list comprehension.
Another way using also a lambda to create a helper:
Bonus: Two ways to do the same in Clojure:
I used a list comprehension.
Another way using also a lambda to create a helper:
Bonus: Two ways to do the same in Clojure:
Sunday, May 6, 2012
Adding a Haskell Brush for SyntaxHighlighter in Blogger
Lately I've written several posts about my first steps in Haskell.
The Haskell syntax in my code samples was not being highlighted because SyntaxHighlighter does not have a brush for Haskell (see syntaxes supported here):
To use it in blogger, I edited the HTML of my blog by adding this line right below the place where the rest of the brush scripts were being loaded:
The Haskell syntax in my code samples was not being highlighted because SyntaxHighlighter does not have a brush for Haskell (see syntaxes supported here):
mulTable n = [[c * b | b <- xs] | c <- [0..n]] !! n where xs = [0..10]Googling a bit I found out that watashi had developed a custom brush for Haskell.
To use it in blogger, I edited the HTML of my blog by adding this line right below the place where the rest of the brush scripts were being loaded:
<script src='http://blog.watashi.ws/wp-content/uploads/2009/12/shBrushHaskell.js' type='text/javascript'/>Then to highlight the syntax of a Haskell code sample, I just did:
<pre class="haskell" name="code"> mulTable n = [[c * b | b <- xs] | c <- [0..n]] !! n where xs = [0..10] </pre>And this was the result:
mulTable n = [[c * b | b <- xs] | c <- [0..n]] !! n where xs = [0..10]
Thursday, May 3, 2012
Playing with Haskell: Multiplication Tables
After reading I'm a list comprehension in Learn You a Haskell for Great Good! book, it came to my mind that I could generate multiplication tables as an initial exercise.
After a bit of trial and error, I managed to group the lists the way I wanted.
This is my clumsy solution:
After a bit of trial and error, I managed to group the lists the way I wanted.
This is my clumsy solution:
mulTable n = [[c * b | b <- xs] | c <- [0..n]] !! n where xs = [0..10]And this is how it's used:
*Main> :l baby.hs [1 of 1] Compiling Main ( baby.hs, interpreted ) Ok, modules loaded: Main. *Main> mulTable 0 [0,0,0,0,0,0,0,0,0,0,0] *Main> mulTable 1 [0,1,2,3,4,5,6,7,8,9,10] *Main> mulTable 2 [0,2,4,6,8,10,12,14,16,18,20] *Main> mulTable 7 [0,7,14,21,28,35,42,49,56,63,70] *Main> mulTable 10 [0,10,20,30,40,50,60,70,80,90,100] *Main> mulTable 12 [0,12,24,36,48,60,72,84,96,108,120] *Main> mulTable 15 [0,15,30,45,60,75,90,105,120,135,150] *Main> mulTable 20 [0,20,40,60,80,100,120,140,160,180,200]@remosu has a simpler and better solution:
mulTable n = [c * n | c <- [1..10]]and he did it also in python:
multable = lambda n: [c * n for c in range(1, 11)]
Saturday, April 14, 2012
Beginning with Haskell
I've recently started to become interested in functional languages, so I decided to give Haskell a try.
To begin with, I'm reading this book:
So far, I'm amazed with the elegance with which Haskell can be used to solve some problems. For instance, at the end of the "Starting Out" chapter, we can find this example of a problem that combines tuples and list comprehensions:
Once I finish this book (this will go slow because of UOC and other projects), I have several other links to continue exploring Haskell:
To begin with, I'm reading this book:
So far, I'm amazed with the elegance with which Haskell can be used to solve some problems. For instance, at the end of the "Starting Out" chapter, we can find this example of a problem that combines tuples and list comprehensions:
"Which right triangle that has integers for all sides and all sides equal to or smaller than 10 has a perimeter of 24?"And this is the solution in Haskell:
ghci> [ (a,b,c) | c <- [1..10], b <- [1..c], a <- [1..b], a^2 + b^2 == c^2, a+b+c == 24]Beautiful!
[(6,8,10)]
Once I finish this book (this will go slow because of UOC and other projects), I have several other links to continue exploring Haskell:
Subscribe to:
Posts (Atom)