Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elm type alias with default values

Tags:

elm

I have a "Block" type alias.

type alias Block = {x:Int, y:Int, color:String}

Is it possible to have default values for x, y and color? Example, I want x and y to be 0 by default and color to be "blue".

like image 817
C.S.Reddy Gadipally Avatar asked May 05 '18 23:05

C.S.Reddy Gadipally


1 Answers

You can't have default values in the way you often can in imperative languages, but this isn't a problem because you can easily define a function that sets the desired defaults:

defaultBlock : Block
defaultBlock = { x = 0, y = 0, color = "blue" }
like image 69
Chad Gilbert Avatar answered Nov 06 '22 07:11

Chad Gilbert