{{ message }}

Instantly share code, notes, and snippets.

# Nicolas Rinaudo nrinaudo

Created Nov 7, 2021
Surprising Java behaviour...
View Trick.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import java.util.List; import java.util.Arrays; import java.util.Collections; class Demo { static class NotComparable {} public static void main(String[] args) { List list = Arrays.asList(new NotComparable(), new NotComparable());
Created Aug 13, 2020
Intro to a hypothetical talk on inheritance that I'll never have the courage to actually give
View inheritance-intro.org

Hello, my name is Nicolas Rinaudo and I’m here today because I’d like to talk to you about one of the core features of our favourite language, one that we, as OOP programmers, should be intimately familiar with: inheritance.

Yes, I’m aware that there’s a fringe of the community that refuses to use inheritance on philosophical grounds, and I respect that. I just think it’s a bit of a shame because honestly, I couldn’t work without algebraic data types, and, well, Scala does them with inheritance. Or without type classes, for that matter - anybody that knows me knows I love my type classes - and they’re also done with inheritance in Haskell. I mean in Scala. Well, in both, really.

Don’t believe me? Here’s what the Haskell documentation has to say on the subject (https://www.haskell.org/tutorial/classes.html):

We say that Eq is a superclass of Ord (conversely, Ord is a subclass of Eq), and any type which is an instance of Ord must also be an instance of Eq.

Last active Aug 3, 2022

# Introduction

I was recently asked to explain why I felt disappointed by Haskell, as a language. And, well. Crucified for crucified, I might as well criticise Haskell publicly.

First though, I need to make it explicit that I claim no particular skill with the language - I will in fact vehemently (and convincingly!) argue that I'm a terrible Haskell programmer. And what I'm about to explain is not meant as The Truth, but my current understanding, potentially flawed, incomplete, or flat out incorrect. I welcome any attempt at proving me wrong, because when I dislike something that so many clever people worship, it's usually because I missed an important detail.

Another important point is that this is not meant to convey the idea that Haskell is a bad language. I do feel, however, that the vocal, and sometimes aggressive, reverence in which it's held might lead people to have unreasonable expectations. It certainly was my case, and the reason I'm writing this.

# Type classes

I love the concept of type class

Created Mar 23, 2019
View library-wip.tla
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 EXTENDS Integers, TLC, Sequences CONSTANTS Books, People, NumCopies ASSUME NumCopies \in Nat \ {0} PT == INSTANCE PT (*--algorithm library
Created Mar 20, 2019
View imageaug.tla
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 ------------------------------ MODULE imageaug ------------------------------ EXTENDS Integers, FiniteSets, TLC CONSTANTS Documents, Models, MaxRetries, NULL ASSUME MaxRetries \in Nat \ {0} ASSUME Cardinality(Documents) /= 0
Created Feb 7, 2019
Using optics to patch Gen instances
View GenLenses.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import monocle.macros._ import org.scalacheck._ import scalaz.scalacheck.ScalaCheckBinding._ // Deep hierarchy of product types. case class Document(author: Author) case class Author(firstName: String, lastName: String, city: City) case class City(name: String, country: Country) case class Country(name: String, continent: Continent) case class Continent(name: String)
Created Jan 6, 2019
View future.md
title layout
Start independent Futures outside of a for-comprehension
article

When working with independent [Futures][Future], make sure not to initialise them inside a for-comprehension.

# Reason

For-comprehension will create a dependency between your [Futures][Future], turning your code synchronous behind your back.

Created Jan 2, 2019
View Test.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 object Test extends App { val benchIterations = 10 val warmupIterations = 10 val repeat = 100000 val a = "foo" val b = 123 def benchOne[U](a : => U): Long = (0 to repeat).foldLeft(0L) { case (total, _) =>
Created Aug 13, 2018