List Info

Thread: "ocaml_beginners"::[] Swapping parameters




"ocaml_beginners"::[] Swapping parameters
country flaguser name
France
2007-09-01 17:17:29

HI !

SOMETIMES IT IS MAYBE USEFUL TO DO THIS :

LET SWAP_PARAMETERS F X Y = F Y X

BUT WHAT COULD BE A GOOD CHOICE FOR AN OPERATOR NAME ?
(|<->) ? MAYBE SOMETHING ELSE IS CURRENTLY USED ?

LET (|<->;) F X Y = F Y X

AS AN EXAMPLE OF USE :

LET FOO X Y = G X Y Z

COULD BE REWRITTEN :

LET BAR X = G |<-> X Z

UGLY ENOUGH... AND MAYBE THE THINGS DO NOT LOOK LIKE VERY SIMPLIFIED ( WE GOT A "|<;->"; INSTEAD OF TWO "Y&QUOT; AND THE CODE SEEMS LESS READABLE).
I WONDER IF THE "Y&QUOT; PARAMETER SUPPRESSION IS'NT HOWEVER HELPFUL BECAUSE IT IS FUNCTIONAL / ABSTRACT A DEGREE FURTHER.
AND SO MORE EASILY REUSABLE ?

PLEASE WHAT IS NORMALLY USED TO SWAP PARAMETERS ?

THANKS,

FABRICE
----------------------
DES MéCANOS, UN MEC...

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] Swapping parameters
country flaguser name
United States
2007-09-02 02:12:53

On Sep 1, 2007, at 5:17 PM, Fabrice Marchant
< fabrice.marchant%40orange.fr">fabrice.marchantorange.fr> wrote:

> Please what is normally used to swap parameters

Haskell just calls this function 'flip' in its prelude. I find that
to be a good name.

William D. Neumann

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] Swapping parameters
country flaguser name
France
2007-09-02 01:43:08

On Sun, 2 Sep 2007 02:12:53 -0500
William Neumann < wneumann%40cs.unm.edu">wneumanncs.unm.edu> wrote:

> Haskell just calls this function 'flip' in its prelude. I find that
> to be a good name.

Thanks a lot William !

So, if Haskell hasn't used any operator, probably we do not need too.
All right for 'flip' : far shorter than 'swap_parameters'.

The list of usually defined operators I've met remains short :

let ( |> ) x f = f x
let ( << ) f g x = f(g x)

Recently seen this on the list :
let ( ) f x = f x;;
( for Haskell $ )

and heard about ( >> ) but do not know what it means.

Best,

Fabrice

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] Swapping parameters
country flaguser name
France
2007-09-03 14:40:49

On Sun, 02 Sep 2007 12:23:30 +0200
Matthieu Dubuget < matthieu.dubuget%40gmail.com">matthieu.dubugetgmail.com> wrote:

> Hello,
&gt;
> The following text is stolen from F# manual pages
&gt; (http://research.microsoft.com/fsharp/manual/quicktour.aspx).
> Hoping this will help?
&gt; Salutations
>
> Matt
>;
>
> The following two important operators are defined in *MLLib.Pervasives*:
>
> let (|>) x f = f x
>
> Pipeline operator
>
> let (>>) f g x = g(f x)
>
> Function composition operator
>
> These are very important in F# code and will be used in many samples you
> see. They are used to pipeline and compose functions. For example:
>
> let allMembers =
> System.AppDomain.CurrentDomain.GetAssemblies()
&gt; |> Array.to_list |> List.map (fun a -> a.GetTypes()) |>
&gt; Array.concat
> |> Array.to_list |> List.map (fun ty -> ty.GetMembers()) |>
&gt; Array.concat;;

Thanks a lot Matt for (>>) operator name and definition !

MS speaks about many examples : I do not see anything about (>>).
I simply notice we have :
(>&gt;) = flip (<<)
There are things for everybody, for semitic languages too.

Cheers,

Fabrice
----------------------------------------------------------
Pesticides -> plus d'abeilles -> plus de pollenisation -> la fin des haricots

__._,_.___
.

__,_._,___
[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )