!OhIqpkyOYphwciwUwE:matrix.org

F-Sharp

91 Members
F# programming language38 Servers

Load older messages


SenderMessageTime
9 Sep 2020
@Vortai:matrix.orgVortaiHowdy, so since I last asked I've made some decent progress, been able to replace parts of my C# code with F# and it all still works.03:48:14
@Vortai:matrix.orgVortaiI've gotten to the point where I'd like to not only replace some of the functions/methods but also the data structures, because F# types are so nice.03:49:15
@Vortai:matrix.orgVortaiHowever because it's a video game, a lot of these data structures are normally rather reliant on being mutable. Some of them I think I know how to work around this, but some are updated from the main loop (called Process).03:50:24
@Vortai:matrix.orgVortaiI'd like to be able to replace those data structures as well but I can't seem to find a better solution than allowing those data structures in F# to be mutable, which means they're basically equivalent at worst but ideally I'd like them to be better.03:51:21
@Vortai:matrix.orgVortaiI'm currently working on trying to convert a C# dictionary to a F# record and have found the copy and update function, but that requires me (reasonably) to provide a new name each time.03:52:44
@stmax:matrix.orgalgo_maxF# and C# mix well, but syntax will never be as nice as pure F#.. switch your main program to F# :)07:13:42
@Vortai:matrix.orgVortaiOh that's the long term goal for sure07:15:29
@Vortai:matrix.orgVortaiInitially I wanted to just rewrite it in F#07:15:38
@Vortai:matrix.orgVortaibut because of some quirks with a library I need to use, I quickly found that very difficult.07:16:01
@Vortai:matrix.orgVortaiby rewrite I mean write from the ground up07:16:12
@Vortai:matrix.orgVortaiSo now I'm replacing/upgrading/rewriting it to find those limitations as I go.07:16:32
@Vortai:matrix.orgVortaispeaking of limitations, do you perchance know of an idiomatic way to do something every x loops?07:23:10
@stmax:matrix.orgalgo_maxSeq.fold could be called an idiomatic way for replacing loops.. add a counter to the state variable and increment / check / reset it every iteration.20:03:48
10 Sep 2020
@phanaeus_phineas:matrix.orgphanPhin changed their display name from phanaeus_phineas to phanPhin.01:48:07
@Vortai:matrix.orgVortai Thanks for that algo_max, but sadly it's not what I need, let me explain it better. 04:29:14
@Vortai:matrix.orgVortaiI'm working with a game engine, and much of it works via the main loop, which I can access like so.04:29:48
@Vortai:matrix.orgVortai
    public override void _Process(float delta)
    {
        //do stuff here
    }
04:30:43
@Vortai:matrix.orgVortaithis is the C# code04:30:50
@Vortai:matrix.orgVortaiNow I can also access it in F# land like so04:31:25
@Vortai:matrix.orgVortai
    override this._PhysicsProcess(delta) =
        mutRest <- updateNeed mutRest
        //do stuff here
04:31:49
@Vortai:matrix.orgVortaiSo I've made an update function that looks like this.04:32:03
@Vortai:matrix.orgVortai
    let updateNeed (need: Need) =
        match (need.DecayDirection, need.Decaying) with
        | (Up,true) | (Down,false) ->
            let newValue = need.CurrentValue + need.ChangeRate
            if newValue > need.Maxi then
                {need with CurrentValue = need.Maxi}
            else  
                {need with CurrentValue = newValue}
        | _ ->
            let newValue = need.CurrentValue - need.ChangeRate
            if newValue < need.Mini then
                {need with CurrentValue = need.Mini}
            else  
                {need with CurrentValue = newValue}
04:32:15
@Vortai:matrix.orgVortaiTo explain I basically have a custom record type which I'm using to build a basic ai that picks from tasks by evaluating it's needs.04:33:10
@Vortai:matrix.orgVortai Current that record isn't mutable at all, but I've got a mutable reference to it let mutable mutRest = rest and then what I'm currently doing is using that to do the update in the main loop. 04:34:06
@Vortai:matrix.orgVortai *
    override this._PhysicsProcess(delta) =
        mutRest <- updateNeed mutRest
        //do stuff here
04:34:30
13 Sep 2020
@hoodedjacket:matrix.orghoodedjacket

Vortai: Have a look at FSharp.Data.Adaptive:
https://github.com/fsprojects/FSharp.Data.Adaptive

It lets you treat mutable values like immutable values in a functional way.

04:26:36
@Vortai:matrix.orgVortaiThank you. I will!07:17:56
14 Sep 2020
@harry:nitro.chatharry 23:18:41
16 Sep 2020
@janjan:synod.im@janjan:synod.im left the room.23:49:31
21 Sep 2020
@milviv:matrix.orgmilviv joined the room.01:31:26

There are no newer messages yet.


Back to Room List