Skip to main content
Code Review

Return to Answer

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

Some remarks :

  • (削除) your combine function is in fact List.zip (削除ここまで), you might want to explore the Array and List sections of the standard library, they are full of very useful functions that will speed-up your development.

  • createRandomBoard is not a function and thus will always be the same array (arrays being mutable, you might come across some unwanted side effects if you use it twice in the same code). It could be rewritten using Array.init :

     let createRandomBoard () =
     let rnd = new Random(10)
     Array.init size (fun _ -> if rnd.NextDouble() < 0.2 then 1 else 0)
    
  • you are using '0' and '1' to model your two states, why not booleans ? It would eliminate the need for some tests.

  • Array.set ar ind x can be rewritten as ar.[ind] <- x (but, as Foggy Finder Foggy Finder said, you would lose some type inference if ar has not been identified as an array before)

  • forms such as :

     [1..n] |> List.iter f
    

are indeed functional but inefficient and, I believe, not as readable as using a loop. F# is especially powerful because it is a hybrid language (and not a purely functional one) : don't hesitate to leverage arrays and loops when it makes sense.

Some remarks :

  • (削除) your combine function is in fact List.zip (削除ここまで), you might want to explore the Array and List sections of the standard library, they are full of very useful functions that will speed-up your development.

  • createRandomBoard is not a function and thus will always be the same array (arrays being mutable, you might come across some unwanted side effects if you use it twice in the same code). It could be rewritten using Array.init :

     let createRandomBoard () =
     let rnd = new Random(10)
     Array.init size (fun _ -> if rnd.NextDouble() < 0.2 then 1 else 0)
    
  • you are using '0' and '1' to model your two states, why not booleans ? It would eliminate the need for some tests.

  • Array.set ar ind x can be rewritten as ar.[ind] <- x (but, as Foggy Finder said, you would lose some type inference if ar has not been identified as an array before)

  • forms such as :

     [1..n] |> List.iter f
    

are indeed functional but inefficient and, I believe, not as readable as using a loop. F# is especially powerful because it is a hybrid language (and not a purely functional one) : don't hesitate to leverage arrays and loops when it makes sense.

Some remarks :

  • (削除) your combine function is in fact List.zip (削除ここまで), you might want to explore the Array and List sections of the standard library, they are full of very useful functions that will speed-up your development.

  • createRandomBoard is not a function and thus will always be the same array (arrays being mutable, you might come across some unwanted side effects if you use it twice in the same code). It could be rewritten using Array.init :

     let createRandomBoard () =
     let rnd = new Random(10)
     Array.init size (fun _ -> if rnd.NextDouble() < 0.2 then 1 else 0)
    
  • you are using '0' and '1' to model your two states, why not booleans ? It would eliminate the need for some tests.

  • Array.set ar ind x can be rewritten as ar.[ind] <- x (but, as Foggy Finder said, you would lose some type inference if ar has not been identified as an array before)

  • forms such as :

     [1..n] |> List.iter f
    

are indeed functional but inefficient and, I believe, not as readable as using a loop. F# is especially powerful because it is a hybrid language (and not a purely functional one) : don't hesitate to leverage arrays and loops when it makes sense.

added 197 characters in body
Source Link

Some remarks :

  • your combine function is in fact List.zip(削除) your combine function is in fact List.zip (削除ここまで), you might want to explore the Array and List sections of the standard library, they are full of very useful functions that will speed-up your development.

  • createRandomBoard is not a function and thus will always be the same array (arrays being mutable, you might come across some unwanted side effects if you use it twice in the same code). It could be rewritten using Array.init :

     let createRandomBoard () =
     let rnd = new Random(10)
     Array.init size (fun _ -> if rnd.NextDouble() < 0.2 then 1 else 0)
    
  • you are using '0' and '1' to model your two states, why not booleans ? It would eliminate the need for some tests.

  • Array.set ar ind x can be rewritten as ar.[ind] <- x (but, as Foggy Finder said, you would lose some type inference if ar has not been identified as an array before)

  • forms such as :

     [1..n] |> List.iter f
    

are indeed functional but inefficient and, I believe, not as readable as using a loop. F# is especially powerful because it is a hybrid language (and not a purely functional one) : don't hesitate to leverage arrays and loops when it makes sense.

Some remarks :

  • your combine function is in fact List.zip, you might want to explore the Array and List sections of the standard library, they are full of very useful functions that will speed-up your development.

  • createRandomBoard is not a function and thus will always be the same array (arrays being mutable, you might come across some unwanted side effects if you use it twice in the same code). It could be rewritten using Array.init :

     let createRandomBoard () =
     let rnd = new Random(10)
     Array.init size (fun _ -> if rnd.NextDouble() < 0.2 then 1 else 0)
    
  • you are using '0' and '1' to model your two states, why not booleans ? It would eliminate the need for some tests.

  • Array.set ar ind x can be rewritten as ar.[ind] <- x

  • forms such as :

     [1..n] |> List.iter f
    

are indeed functional but inefficient and, I believe, not as readable as using a loop. F# is especially powerful because it is a hybrid language (and not a purely functional one) : don't hesitate to leverage arrays and loops when it makes sense.

Some remarks :

  • (削除) your combine function is in fact List.zip (削除ここまで), you might want to explore the Array and List sections of the standard library, they are full of very useful functions that will speed-up your development.

  • createRandomBoard is not a function and thus will always be the same array (arrays being mutable, you might come across some unwanted side effects if you use it twice in the same code). It could be rewritten using Array.init :

     let createRandomBoard () =
     let rnd = new Random(10)
     Array.init size (fun _ -> if rnd.NextDouble() < 0.2 then 1 else 0)
    
  • you are using '0' and '1' to model your two states, why not booleans ? It would eliminate the need for some tests.

  • Array.set ar ind x can be rewritten as ar.[ind] <- x (but, as Foggy Finder said, you would lose some type inference if ar has not been identified as an array before)

  • forms such as :

     [1..n] |> List.iter f
    

are indeed functional but inefficient and, I believe, not as readable as using a loop. F# is especially powerful because it is a hybrid language (and not a purely functional one) : don't hesitate to leverage arrays and loops when it makes sense.

explaining the "createRandomBoard is not a function"
Source Link

Some remarks :

  • your combine function is in fact List.zip, you might want to explore the Array and List sections of the standard library, they are full of very useful functions that will speed-up your development.

  • createRandomBoard is not a function and thus will always be the same array (arrays being mutable, you might come across some unwanted side effects if you use it twice in the same code). It could be rewritten using Array.init :

     let createRandomBoard () =
     let rnd = new Random(10)
     Array.init size (fun _ -> if rnd.NextDouble() < 0.2 then 1 else 0)
    
  • you are using '0' and '1' to model your two states, why not booleans ? It would eliminate the need for some tests.

  • Array.set ar ind x can be rewritten as ar.[ind] <- x

  • forms such as :

     [1..n] |> List.iter f
    

are indeed functional but inefficient and, I believe, not as readable as using a loop. F# is especially powerful because it is a hybrid language (and not a purely functional one) : don't hesitate to leverage arrays and loops when it makes sense.

Some remarks :

  • your combine function is in fact List.zip, you might want to explore the Array and List sections of the standard library, they are full of very useful functions that will speed-up your development.

  • createRandomBoard is not a function and could be rewritten using Array.init :

     let createRandomBoard () =
     let rnd = new Random(10)
     Array.init size (fun _ -> if rnd.NextDouble() < 0.2 then 1 else 0)
    
  • you are using '0' and '1' to model your two states, why not booleans ? It would eliminate the need for some tests.

  • Array.set ar ind x can be rewritten as ar.[ind] <- x

  • forms such as :

     [1..n] |> List.iter f
    

are indeed functional but inefficient and, I believe, not as readable as using a loop. F# is especially powerful because it is a hybrid language (and not a purely functional one) : don't hesitate to leverage arrays and loops when it makes sense.

Some remarks :

  • your combine function is in fact List.zip, you might want to explore the Array and List sections of the standard library, they are full of very useful functions that will speed-up your development.

  • createRandomBoard is not a function and thus will always be the same array (arrays being mutable, you might come across some unwanted side effects if you use it twice in the same code). It could be rewritten using Array.init :

     let createRandomBoard () =
     let rnd = new Random(10)
     Array.init size (fun _ -> if rnd.NextDouble() < 0.2 then 1 else 0)
    
  • you are using '0' and '1' to model your two states, why not booleans ? It would eliminate the need for some tests.

  • Array.set ar ind x can be rewritten as ar.[ind] <- x

  • forms such as :

     [1..n] |> List.iter f
    

are indeed functional but inefficient and, I believe, not as readable as using a loop. F# is especially powerful because it is a hybrid language (and not a purely functional one) : don't hesitate to leverage arrays and loops when it makes sense.

Source Link
Loading
lang-ml

AltStyle によって変換されたページ (->オリジナル) /