This file contains hidden or 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 scalaz.Functor | |
import scalaz.Free | |
sealed trait Term[+A] | |
object Term { | |
case object Zero extends Term[Nothing] | |
case class Id[A](term: A) extends Term[A] | |
implicit val termFunctor: Functor[Term] = new Functor[Term] { | |
def map[A, B](fa: Term[A])(f: A => B): Term[B] = fa match { |
This file contains hidden or 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 Control.Applicative | |
import Data.Tuple (swap) | |
{- Given a list of tuples, return a list containing the initial elements and the swapped elements | |
It's an easy one to start the week. | |
Example | |
> appendSwapped [(1,2),(2,3)] | |
[(1,2),(2,3),(2,1),(3,2)] | |
-} |
This file contains hidden or 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 Control.Applicative | |
import Data.Tuple | |
{- Yesterday, we appended swapped values: | |
Example | |
> appendSwapped [(1,2),(2,3)] | |
[(1,2),(2,3),(2,1),(3,2)] | |
-} | |
appendSwapped :: [(a,a)] -> [(a,a)] |
This file contains hidden or 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 Data.Map hiding (foldr) | |
{-| Count character occurrences in a string | |
Examples: | |
>>> lookup 'l' $ countOccurrences "hello" | |
Just 2 | |
>>> lookup 'n' $ countOccurrences "hello" | |
Nothing | |
-} |
This file contains hidden or 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 Control.Applicative | |
{- You have a list of rooms, each rooms has two doors and contain one element. | |
To enter a room, the first door must be opened. To leave a room, the second door | |
must be open. It means that if you want to move from one room to the next one, | |
both the second door of the first room and the first door of the second room. | |
-} | |
data Room a = Room (Bool, Bool) a | |
{- | Given a list of rooms, we want to go as far as we can and collect the elements |
This file contains hidden or 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 Control.Applicative | |
{- We still have yesterday's room | |
-} | |
data Room a = Room {doors :: (Bool, Bool), content :: a} | |
deriving (Eq) | |
{- | Given a list of rooms, we want to go as far as we can and collect the elements | |
in he room, **starting from the last room**. |
This file contains hidden or 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
{-# LANGUAGE TupleSections #-} | |
-- Follow the type and the properties | |
f :: Either a a -> (Bool, a) | |
f = either (False,) (True,) | |
g :: (Bool, a) -> Either a a | |
g (False, a) = Left a | |
g (True, a) = Right a |
This file contains hidden or 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
{-| Keep equal elements that are at the same position in both lists | |
Examples: | |
>>> keepEqual "hello" "world" | |
"l" | |
>>> keepEqual (repeat 1) [0..10] | |
[1] |
This file contains hidden or 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 Data.Tuple | |
{-- | |
Okay, shoot! Fell asleep while composing a problem; sorry for the delay! | |
So, this one is an easy one. We get a little Forth'y'. This is from P19 | |
of the P99 problem-set. | |
--} |
This file contains hidden or 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
« Mais c'est précisément parce que j'attends peu de chose de la condition humaine, les périodes de bonheur, les progrès partiels, les efforts de recommencement et de continuité me semblent autant de prodiges qui compensent presque l'immense masse des maux, des échecs, de l'incurie et de l'erreur. Les catastrophes et les ruines viendront ; le désordre triomphera, mais de temps en temps l'ordre aussi. La paix s'installera de nouveau entre deux périodes de guerre ; les mots de liberté, d'humanité, de justice retrouveront çà et là le sens que nous avons tenté de leur donner. » | |
– Marguerite Yourcenar, « Mémoires d'Hadrien » |