You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.
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:
openFreya.Core.OperatorsletmyFunctionwith' some args =(...)letmyValueInAFreya=
freya {return"some stuff"}letmyValueNotInAFreya="some stuff"letmyPartiallyAppliedOne= myFunction <!> myValueInAFreya
// Above is now Freya<'a->'b->'c>// I want to add another arg partially appliedletmyPartiallyAppliedTwo= 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:
letmyFunctionNotInAFreya some arg =(...)letmyFunctionReturningAFreyaWrappedFun()=
freya {return(fun x -> x.ToString())}//this gives me nested Freyas:letnormalMap= myFunctionNotInAFreya <!>(myFunctionReturningAFreyaWrappedFun ())// above gives `Freya<Freya<'a->'b>>`// using my operator:letasExpected= myFunctionNotInAFreya <^!>(myFunctionReturningAFreyaWrappedFun ())//above gives `Freya<'a->'b>`as expected.
This may or may not be something to include as part of the core operators..
The text was updated successfully, but these errors were encountered:
I don't see why not :) There are ways of writing them using the more "common" operators, but they're less concise, and we wouldn't be mandating these. I think this would be fine, but I'd probably add them to an extra module under Freya.Operators - something like Freya.Operators.Extended to signify that these are probably a bit more special purpose. But I'd be happy to take that I think!
Just for my education: would you mind giving an example of how to to this with the "common" operators. And perhaps also give some suggestion on what to name my shortcuts?
Not sure how clear this is, but maybe useful - and I think doing the same thing! The first one is slightly awkward, although could be slightly tidied up by defining a function let apply a b = b a and then replacing the function definition with simply apply x as shown:
// Firstlet(<!^>)f v =
freya {let!f= f
return f v }letdouble=
freya {return(fun x -> x *2)}letdoubled x =
double <!^> x
// orletdoubled' x =(fun f -> f x)<!> double
// orletapply a b =
b a
letdoubled'' x =
apply x <!> double
// Secondlet(<^!>)f v =
freya {let!v= v
return! f v }lettriple x =
freya {return x *3}lettripled x =
triple <^!> Freya.init x
// orlettripled' x =
Freya.init x >>= triple // or: triple =<< Freya.init x
Hopefully that's useful?
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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:
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:
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:
This may or may not be something to include as part of the core operators..
The text was updated successfully, but these errors were encountered: