$ operator like in Haskell?

69 views
Skip to first unread message

Robert Kuzelj

unread,
Oct 26, 2015, 10:31:13 AM10/26/15
to F# Discussions
Hi,

is there something like the $ in Haskell for F#?

cant find it (and its hard to Google "F# $" ;-) )

Best regards

Robert

Isaac Abraham

unread,
Oct 26, 2015, 10:41:47 AM10/26/15
to fsharp-o...@googlegroups.com

I believe that this is the <| operator.

--
--
To post, send email to fsharp-o...@googlegroups.com
To unsubscribe, send email to
fsharp-opensou...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/fsharp-opensource
---
You received this message because you are subscribed to the Google Groups "F# Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fsharp-opensou...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Steffen Forkmann

unread,
Oct 26, 2015, 10:44:04 AM10/26/15
to fsharp-o...@googlegroups.com

Hi,

 

($) :: (a -> b) -> a -> b (see https://www.haskell.org/hoogle/?hoogle=%24 )

 

In F# we have <| with same signature.

 

Cheers,

Steffeb

--

--
To post, send email to

Robert Kuzelj

unread,
Oct 26, 2015, 11:46:37 AM10/26/15
to F# Discussions

hmm, I expected something differentgiven this 2 definitions

type Length = Auto | Star of float | Absolute of float
let filled expand xs = ...

What I want to do is this (which gives me an error)

filled true <| List.replicate 12 <| Star 1.0

whereas these will not

filled true (List.replicate 12 (Star 1.0))  // this one is obvious
filled true <| List.replicate 12 (Star 1.0)  // this one works
filled true (List.replicate 12 <| Star 1.0)  // this one as well

Am Montag, 26. Oktober 2015 15:44:04 UTC+1 schrieb Steffen Forkmann:

Hi,

 

($) :: (a -> b) -> a -> b (see https://www.haskell.org/hoogle/?hoogle=%24 )

 

In F# we have <| with same signature.

 

Cheers,

Steffeb

 

Von: fsharp-o...@googlegroups.com [mailto:fsharp-o...@googlegroups.com] Im Auftrag von Robert Kuzelj
Gesendet: Montag, 26. Oktober 2015 15:31
An: F# Discussions <fsharp-o...@googlegroups.com>
Betreff: $ operator like in Haskell?

 

Hi,

 

is there something like the $ in Haskell for F#?

 

cant find it (and its hard to Google "F# $" ;-) )

 

Best regards

 

Robert

--
--
To post, send email to
fsharp-opensource@googlegroups.com


To unsubscribe, send email to

Don Syme

unread,
Oct 26, 2015, 12:41:28 PM10/26/15
to fsharp-o...@googlegroups.com

 

Hi Robert,

 

In idiomatic F# you use the pipe-forward operator for this:

 

Star 1.0 |> List.replicate 12 |> filled true

 

Cheers

Don

 

 

From: fsharp-o...@googlegroups.com [mailto:fsharp-o...@googlegroups.com] On Behalf Of Robert Kuzelj


Sent: 26 October 2015 15:47
To: F# Discussions <fsharp-o...@googlegroups.com>

--
--
To post, send email to
fsharp-o...@googlegroups.com


To unsubscribe, send email to


For more options, visit this group at
http://groups.google.com/group/fsharp-opensource
---
You received this message because you are subscribed to the Google Groups "F# Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fsharp-opensou...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
--
To post, send email to fsharp-o...@googlegroups.com


To unsubscribe, send email to

Robert Kuzelj

unread,
Oct 26, 2015, 1:28:34 PM10/26/15
to F# Discussions
Hi Don,

yeah I know <sigh>
yet that idiomatic usage is somehow incompatible with the idiomatic usage of the DSL I am creating :-(

Seems like I am stuck with parens then

--
--
To post, send email to
fsharp-opensource@googlegroups.com


To unsubscribe, send email to


For more options, visit this group at
http://groups.google.com/group/fsharp-opensource
---
You received this message because you are subscribed to the Google Groups "F# Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fsharp-opensou...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bryan Edds

unread,
Oct 26, 2015, 3:46:45 PM10/26/15
to F# Discussions
Unfortunately, (<|) has incorrect associativity for what's almost always intended. Just use the following operator by defining it yourself, of pulling it in from FSharpx -

    /// Sequences two functions like Haskell ($).
    let inline (^) f g = f g

Also unfortunately, (|>) is inferior to (^) in the context of certain monads. For example, look at the do! loop combinator -

                let chain = chain {
                    do! update ^ Simulants.HudSaveGame.SetEnabled false
                    do! loop 0 inc (fun i world -> i = 0 || anyTurnsInProgress world) ^ fun i -> chain {
                        let! evt = next
                        do! match event_.Data with
                            | Right _ -> chain {
                                let! playerTurn =
                                    if i = 0
                                    then getBy ^ determinePlayerTurnFromInput playerInput
                                    else getBy ^ determinePlayerTurn
                                do! update ^ runPlayerTurn playerTurn }
                            | Left _ -> chain {
                                do! update ^ cancelNavigation Simulants.Player }}
                    do! update ^ Simulants.HudSaveGame.SetEnabled true }

Attempting to reverse that by using the (|>) approach is only going to hurt you.

On the other hand, (<|) is almost never the correct approach.
Reply all
Reply to author
Forward
0 new messages