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
fibs :: Num a => [a] | |
fibs = 0 : 1 : zipWith (+) fibs (tail fibs) | |
isEven :: Integral a => a -> Bool | |
isEven x = x `mod` 2 == 0 | |
main :: IO () | |
main = print $ takeWhile (\x -> x <= 4000000) (filter isEven fibs) | |
-- [0,2,8,34,144,610,2584,10946,46368,196418,832040,3524578] |
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
interface MonoidCtor<A> { | |
new (a: any): Monoid<A>; | |
of (value: any): Monoid<A>; | |
empty (): Monoid<A>; | |
concat: (a: Monoid<A>) => (b: Monoid<A>) => Monoid<A>; | |
reify: (a: Monoid<A>) => A; | |
} | |
interface Monoid<A> { | |
empty: () => 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
interface MonoidCtor<A> { | |
new (a: any): Monoid<A>; | |
of (value: any): Monoid<A>; | |
empty (): Monoid<A>; | |
concat: (a: Monoid<A>) => (b: Monoid<A>) => Monoid<A>; | |
} | |
interface Monoid<A> { | |
empty: () => Monoid<A>; | |
concat: (a: Monoid<A>) => Monoid<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
interface MonoidCtor<A> { | |
new (a: any): Monoid<A>; | |
of (value: any): Monoid<A>; | |
empty (): Monoid<A>; | |
concat: (a: Monoid<A>) => (b: Monoid<A>) => Monoid<A>; | |
} | |
interface Monoid<A> { | |
empty: () => A; | |
concat: (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
interface Monoid<A> { | |
empty: () => A; | |
concat: (a: A) => A; | |
} | |
class Sum implements Monoid<Sum> { | |
public static of(value: number) { | |
return new Sum(value); | |
} |
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
interface Monoid<A, B> { | |
mempty: () => Monoid<A, B>; | |
mconcat: (r: Monoid<A, B>) => Monoid<A, B>; | |
runMonoid: () => B; | |
} | |
const mconcat = <A, B>(a : Monoid<A, B>) => (b: Monoid<A, B>): Monoid<A, B> => a.mconcat(b); | |
class Sum implements Monoid<Sum, number> { | |
constructor(private value: number) {} |
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 fl = require('fantasy-land'); | |
interface ILeft<A> { | |
_: 'Left'; | |
value: A; | |
} | |
interface IRight<B> { | |
_: 'Right'; | |
value: B; |
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
interface INothing { | |
_: 'Nothing'; | |
} | |
interface IJust<A> { | |
_: 'Just'; | |
value: A; | |
} | |
type Maybe<A> = INothing | IJust<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
const xxx = | |
prK => | |
prV => | |
mapK => | |
mapV => | |
obj => Object.entries(obj).reduce( | |
(obj, [key, value]) => | |
({ | |
...obj, | |
...(prK(key) && prV(value) ? {[mapK(key)]: mapV(value)} : {}) |
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
data Instruction = F | B | L | R | |
data Direction = N | S | E | W | |
deriving Eq | |
data Position = Position Integer Integer | |
deriving Eq | |
data WorldState = WorldState { roverPosition :: Position, roverDirection :: Direction, width :: Integer, height :: Integer, obstacles :: [Position] } | |
deriving Eq | |
step :: WorldState -> Instruction -> WorldState |