开发者

Scrambled looking records in F#-Interactive

开发者 https://www.devze.com 2023-03-28 10:52 出处:网络
When trying to print pop I get all this weird looking formatting in F# interactive, which basically turns the printing useless. Is there someway other to correctly format this?

When trying to print

pop

I get all this weird looking formatting in F# interactive, which basically turns the printing useless. Is there someway other to correctly format this?

Scrambled looking records in F#-Interactive

The code is the following:

#light

open System
let rng = new Random()

type Individual = { x:int; y:int }
type ScoredIndividual = { individual:Individual; score:int }

let genGene() = rng.Next(-10, 10)
let genRandInd() = { x=genGene(); y=genGene() }
let genRandPop popSize = [ for _ in 1 .. popSize -> genRandInd() ]
let getScoredPop f pop = List.map (fun i -> { individual=i; score=(f i)}) pop

let fitnessFun ind = ind.x * ind.x + ind.y * ind.y

let pop = 30 |> ge开发者_如何学PythonnRandPop |> getScoredPop fitnessFun


You can override ToString or use StructuredFormatDisplayAttribute to customize the string representation. This article contains some useful information about customizing output in fsi.


you might want to do fsi.AddPrinter for your ScoredIndividual type to control what's written to the console


That's pretty rough, and I couldn't find any "easy" way to fix it. However, FsEye can make it nicer (while it does delete the newlines, those spaces are in there good):

Scrambled looking records in F#-Interactive

0

精彩评论

暂无评论...
验证码 换一张
取 消