3 ms·
F# supports piping to a level that Bash et al can only dream of.
by nbevans 13y ago
F# supports piping to a level that Bash et al can only dream of.
- Touche 13y agoCode example?
- nbevans 13y agohttp://www.tryfsharp.org/Learn/getting-started#chaining-functions http://www.tryfsharp.org/Learn/getting-started#chaining-func... http://www.tryfsharp.org/Learn/advanced-programming#currying http://www.tryfsharp.org/Learn/advanced-programming#currying
- Touche 13y agoBoth of those links require a browser plugin that I'm not going to install. From the url's I'm guessing this is about piping functions? I'm not asking about that, I'm asking about piping commands (programs), something any shell scripting language needs to be able to do.
- MichaelGG 13y agoIMO the problem with bash piping is that it's just text streams. Which means you end up having to do all sorts of text manipulation tasks if something outputs a complex object. Compare to, say, PowerShell, which pipes objects along. You can treat them as a text representation, or operate on their properties without having to embed a little parser. I'm not sure what about F#'s piping syntax (it's just reversed function application) blows bash away, though. FWIW: F# ships a standard definition for the operator |> as "let (|>) x f = f x". Hence you can do e.g. "123 |> write" instead of "write 123". In practise this leads to normal chaining of map/reduce and other list manipulations. In F#, this operator also gains attention as F#'s inference is left-to-right, so suppose you have a list of strings "xs". Without piping, you might write: let firstChars xs = Seq.map (fun (x: string) -> xs.[0]) xs With pipeline it becomes: let firstChars xs = xs |> Seq.map (fun x -> xs.[0])
- Touche 13y agoAgain, you are piping functions, not programs. Piping programs is important to shell scripting. This is actually very hard in PowerShell. I've written a few cmdlets; it is hard. And even harder for the user.
- profquail 13y agoCan you provide an example of some task which is easy in a shell script (sh) and difficult in PowerShell? Perhaps something related to piping? I've written a few .sh scripts here and there and I use PowerShell occasionally; I'm nowhere near an expert in either though, so a concrete example would make it easier to understand your point about PowerShell being more difficult.
- Touche 13y agoSomeone else provided an example of zipping a file.