hello question list expressions in f#. try create record stored in list. want point
record inside square
record update 1-9. clear out mean it's when write let example = [1 .. 1 .. 9]
, get: val example : int list = [1; 2; 3; 4; 5; 6; 7; 8; 9]
. here want point
in square
record change pos = {x=1; y=1}
, 9 squares points x=1; y=1
x=9; y=9
.
type point = {x : int; y : int} type square = {pos : point; side : int; x : int} //a square got position, side length , value let defaultsquare = { pos = {x=1; y=1}; side = 10; x = 0 } let spelplan = [{defaultsquare pos = {x=1; y=1}} .. {defaultsquare pos = {x=9; y=9}}]
i've tried code above, i've tried.
let spelplan = [{defaultsquare pos = {x=1; y=1}} .. {defaultsquare pos = {x=1; y=1}} .. {defaultsquare pos = {x=9; y=9}}]
i error message doesn't support +
operator.
the reason code not working expect is, f# not know how enumerate square
s - try implement +
, stuff instead create positions (using said list expressions) , map them square list
:
let frompos size v x y = { pos = {x=x; y=y} ; side = size ; x = v } [for y in 1..9 x in 1..9 -> frompos 10 0 x y]
as alternative can do
[for y in 1..9 x in 1..9 -> (x,y)] |> list.map (fun (x,y) -> frompos 10 0 x y)
as of course
the interesting thing here surley way produce positions - can generalize this:
let positions width height = [ y in 1..height x in 1..width -> (x,y) ]
which produce list of (x,y)
-tuples (1,1)
(width,height)
Comments
Post a Comment