Skip to content

Instantly share code, notes, and snippets.

@Ryan1729
Created October 30, 2016 09:37
Show Gist options
  • Save Ryan1729/a60784a9acf82d461debd7aedebe190e to your computer and use it in GitHub Desktop.
Save Ryan1729/a60784a9acf82d461debd7aedebe190e to your computer and use it in GitHub Desktop.
elm compile speed comparison
module Main exposing (..)
type BoardId
= ZeroZero
| ZeroOne
| ZeroTwo
| OneZero
| OneOne
| OneTwo
| TwoZero
| TwoOne
| TwoTwo
type Board
= EmptyBoard
| OneByOne Int
| OneByTwo Int Int
| OneByThree Int Int Int
| TwoByTwo
{ zeroZero : Int
, zeroOne : Int
, oneZero : Int
, oneOne : Int
}
| TwoByThree
{ zeroZero : Int
, zeroOne : Int
, zeroTwo : Int
, oneZero : Int
, oneOne : Int
, oneTwo : Int
}
| ThreeByThree
{ zeroZero : Int
, zeroOne : Int
, zeroTwo : Int
, oneZero : Int
, oneOne : Int
, oneTwo : Int
, twoOne : Int
, twoZero : Int
, twoTwo : Int
}
get : BoardId -> Board -> Maybe Int
get boardId board =
case board of
EmptyBoard ->
Nothing
OneByOne int ->
case boardId of
ZeroZero ->
Just int
_ ->
Nothing
OneByTwo i0 i1 ->
case boardId of
ZeroZero ->
Just i0
ZeroOne ->
Just i1
_ ->
Nothing
OneByThree i0 i1 i2 ->
case boardId of
ZeroZero ->
Just i0
ZeroOne ->
Just i1
ZeroTwo ->
Just i2
_ ->
Nothing
TwoByTwo r ->
case boardId of
ZeroZero ->
Just r.zeroZero
ZeroOne ->
Just r.zeroOne
OneZero ->
Just r.oneZero
OneOne ->
Just r.oneOne
_ ->
Nothing
TwoByThree r ->
case boardId of
ZeroZero ->
Just r.zeroZero
ZeroOne ->
Just r.zeroOne
ZeroTwo ->
Just r.zeroTwo
OneZero ->
Just r.oneZero
OneOne ->
Just r.oneOne
OneTwo ->
Just r.oneTwo
_ ->
Nothing
ThreeByThree r ->
case boardId of
ZeroZero ->
Just r.zeroZero
ZeroOne ->
Just r.zeroOne
ZeroTwo ->
Just r.zeroTwo
OneZero ->
Just r.oneZero
OneOne ->
Just r.oneOne
OneTwo ->
Just r.oneTwo
TwoZero ->
Just r.twoZero
TwoOne ->
Just r.twoOne
TwoTwo ->
Just r.twoTwo
set : BoardId -> Int -> Board -> Board
set boardId int board =
case board of
EmptyBoard ->
case boardId of
ZeroZero ->
OneByOne int
_ ->
board
OneByOne _ ->
case boardId of
ZeroZero ->
OneByOne int
_ ->
board
OneByTwo i0 i1 ->
case boardId of
ZeroZero ->
OneByTwo int i1
ZeroOne ->
OneByTwo i0 int
_ ->
board
OneByThree i0 i1 i2 ->
case boardId of
ZeroZero ->
OneByThree int i1 i2
ZeroOne ->
OneByThree i0 int i2
ZeroTwo ->
OneByThree i0 i1 int
_ ->
board
TwoByTwo r ->
case boardId of
ZeroZero ->
TwoByTwo { r | zeroZero = int }
ZeroOne ->
TwoByTwo { r | zeroOne = int }
OneZero ->
TwoByTwo { r | oneZero = int }
OneOne ->
TwoByTwo { r | oneOne = int }
_ ->
board
TwoByThree r ->
case boardId of
ZeroZero ->
TwoByThree { r | zeroZero = int }
ZeroOne ->
TwoByThree { r | zeroOne = int }
ZeroTwo ->
TwoByThree { r | zeroTwo = int }
OneZero ->
TwoByThree { r | oneZero = int }
OneOne ->
TwoByThree { r | oneOne = int }
OneTwo ->
TwoByThree { r | oneTwo = int }
_ ->
board
ThreeByThree r ->
case boardId of
ZeroZero ->
ThreeByThree { r | zeroZero = int }
ZeroOne ->
ThreeByThree { r | zeroOne = int }
ZeroTwo ->
ThreeByThree { r | zeroTwo = int }
OneZero ->
ThreeByThree { r | oneZero = int }
OneOne ->
ThreeByThree { r | oneOne = int }
OneTwo ->
ThreeByThree { r | oneTwo = int }
TwoZero ->
ThreeByThree { r | twoZero = int }
TwoOne ->
ThreeByThree { r | twoOne = int }
TwoTwo ->
ThreeByThree { r | twoTwo = int }
module Main exposing (..)
type BoardId
= ZeroZero
| ZeroOne
| ZeroTwo
| OneZero
| OneOne
| OneTwo
| TwoZero
| TwoOne
| TwoTwo
type Board
= EmptyBoard
| OneByOne Int
| OneByTwo Int Int
| OneByThree Int Int Int
| TwoByTwo
{ zeroZero : Int
, zeroOne : Int
, oneZero : Int
, oneOne : Int
}
| TwoByThree
{ zeroZero : Int
, zeroOne : Int
, zeroTwo : Int
, oneZero : Int
, oneOne : Int
, oneTwo : Int
}
| ThreeByThree
{ zeroZero : Int
, zeroOne : Int
, zeroTwo : Int
, oneZero : Int
, oneOne : Int
, oneTwo : Int
, twoOne : Int
, twoZero : Int
, twoTwo : Int
}
get : BoardId -> Board -> Maybe Int
get boardId board =
case ( boardId, board ) of
( ZeroZero, EmptyBoard ) ->
Nothing
( ZeroZero, OneByOne int ) ->
Just int
( ZeroOne, OneByTwo i0 _ ) ->
Just i0
( ZeroZero, OneByTwo _ i1 ) ->
Just i1
( ZeroOne, OneByThree i0 _ _ ) ->
Just i0
( ZeroZero, OneByThree _ i1 _ ) ->
Just i1
( ZeroZero, OneByThree _ _ i2 ) ->
Just i2
( ZeroZero, TwoByThree r ) ->
Just r.zeroZero
( ZeroOne, TwoByThree r ) ->
Just r.zeroOne
( ZeroTwo, TwoByThree r ) ->
Just r.zeroTwo
( OneZero, TwoByThree r ) ->
Just r.oneZero
( OneOne, TwoByThree r ) ->
Just r.oneOne
( OneTwo, TwoByThree r ) ->
Just r.oneTwo
( ZeroZero, ThreeByThree r ) ->
Just r.zeroZero
( ZeroOne, ThreeByThree r ) ->
Just r.zeroOne
( ZeroTwo, ThreeByThree r ) ->
Just r.zeroTwo
( OneZero, ThreeByThree r ) ->
Just r.oneZero
( OneOne, ThreeByThree r ) ->
Just r.oneOne
( OneTwo, ThreeByThree r ) ->
Just r.oneTwo
( TwoZero, ThreeByThree r ) ->
Just r.twoZero
( TwoOne, ThreeByThree r ) ->
Just r.twoOne
( TwoTwo, ThreeByThree r ) ->
Just r.twoTwo
set : BoardId -> Int -> Board -> Board
set boardId int board =
case ( boardId, board ) of
( ZeroZero, EmptyBoard ) ->
OneByOne int
( ZeroZero, OneByOne _ ) ->
OneByOne int
( ZeroZero, OneByTwo _ i1 ) ->
OneByTwo int i1
( ZeroOne, OneByTwo i0 _ ) ->
OneByTwo int i0
( ZeroZero, OneByThree _ i1 i2 ) ->
OneByThree int i1 i2
( ZeroOne, OneByThree i0 _ i2 ) ->
OneByThree i0 int i2
( ZeroTwo, OneByThree i0 i1 _ ) ->
OneByThree i0 i1 int
( ZeroZero, TwoByTwo r ) ->
TwoByTwo { r | zeroZero = int }
( ZeroOne, TwoByTwo r ) ->
TwoByTwo { r | zeroOne = int }
( OneZero, TwoByTwo r ) ->
TwoByTwo { r | oneZero = int }
( OneOne, TwoByTwo r ) ->
TwoByTwo { r | oneOne = int }
( ZeroZero, TwoByThree r ) ->
TwoByThree { r | zeroZero = int }
( ZeroOne, TwoByThree r ) ->
TwoByThree { r | zeroOne = int }
( ZeroTwo, TwoByThree r ) ->
TwoByThree { r | zeroTwo = int }
( OneZero, TwoByThree r ) ->
TwoByThree { r | oneZero = int }
( OneOne, TwoByThree r ) ->
TwoByThree { r | oneOne = int }
( OneTwo, TwoByThree r ) ->
TwoByThree { r | oneTwo = int }
( ZeroZero, ThreeByThree r ) ->
ThreeByThree { r | zeroZero = int }
( ZeroOne, ThreeByThree r ) ->
ThreeByThree { r | zeroOne = int }
( ZeroTwo, ThreeByThree r ) ->
ThreeByThree { r | zeroTwo = int }
( OneZero, ThreeByThree r ) ->
ThreeByThree { r | oneZero = int }
( OneOne, ThreeByThree r ) ->
ThreeByThree { r | oneOne = int }
( OneTwo, ThreeByThree r ) ->
ThreeByThree { r | oneTwo = int }
( TwoZero, ThreeByThree r ) ->
ThreeByThree { r | twoZero = int }
( TwoOne, ThreeByThree r ) ->
ThreeByThree { r | twoOne = int }
( TwoTwo, ThreeByThree r ) ->
ThreeByThree { r | twoTwo = int }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment