Skip to content
This repository was archived by the owner on Feb 22, 2022. It is now read-only.
This repository was archived by the owner on Feb 22, 2022. It is now read-only.

[Suggestion] Combinator operators for partial application of functions wrapped in Freya computations #189

@Vidarls

Description

@Vidarls

As I previously mentioned in #182 I've had some issues getting to grips being inside / outside Freya computations. Particularly with regards to passing around partially applied functions that requires arguments from inside a Freya computation, (and thus themselves get wrapped in a Freya computation after..)

I ended up creating the some custom operators (again).

(Btw, I really wish F# would support named operators, rather than just symbolic ones, would help readability a lot..)

I do have a lot of holes in my functional vocabulary, so I have no idea what to actually call these but here they are:

let (<!^>) f v = 
    freya {
        let! f = f 
        return f v
    } 

let (<^!>) f v = 
    freya {
        let! v = v
        return! f v
    }

The first operator will take a function wrapped in a Freya computation, "dereference" it(?) and apply the given argument, returning the result wrapped in a Freya computation.

Example:

open Freya.Core.Operators

let myFunction with' some args = 
    (...)

let myValueInAFreya = 
    freya {
        return "some stuff"
    }

let myValueNotInAFreya = 
    "some stuff"
let myPartiallyAppliedOne = myFunction <!> myValueInAFreya
// Above is now Freya<'a->'b->'c>
// I want to add another arg partially applied

let myPartiallyAppliedTwo = myPartiallyAppliedOne <!^> myValueNotInAFreya
// Above is now Freya<'a->'b>

It is possible I have misunderstood something, but adding the new operator helped me quite a bit..

The scenario for the other operator is a bit more weird. I ended up creating it because using the standard <!> map(?) operator ended up giving med nested Freyas (Freya<Freya<'t>>) which I was not what I was looking for.

Example:

let myFunctionNotInAFreya some arg = 
    (...)

let myFunctionReturningAFreyaWrappedFun () = 
    freya {
        return (fun x -> x.ToString())
    }

//this gives me nested Freyas:

let normalMap = myFunctionNotInAFreya <!> (myFunctionReturningAFreyaWrappedFun ())
// above gives `Freya<Freya<'a->'b>>`

// using my operator:
let asExpected = myFunctionNotInAFreya <^!> (myFunctionReturningAFreyaWrappedFun ())
//above gives `Freya<'a->'b>`as expected.

This may or may not be something to include as part of the core operators..

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions