Currently, there is no example in the tutorial for the compatibility with Haskell.
There are the following samples:
So perhaps having links to these files would help?
Yep.
By pure causality, yesterday I almost copy the sample files to the docs for the Haskell Compatibility. In the end I decided that I would want to review the code and that will take me some time (which yesterday I didn't had). So let's discuss a bit how to organize this samples in the docs.
As I said yesterday in another discussion, I see an overlap between the samples and the docs, since the docs also contain sample and my guess is that we should move all the samples to the doc. Again this is not just copy-paste, it will require adding some explanations to the sample code.
By pure causality, I almost suggested to actually copy the sample files and was then concerned that this is too much code for this overview. IMHO, a more generic and simple example is suitable.
Operation | F#+ / F# | F#+ Haskell Compatibility | Haskell
-- | -- | -- | --
List.append | @ | 聽 | ++
聽 | << | 聽 | .
聽 | <| | $ | $
聽 | = | == | ==
聽 | <> | =/ | =/
flip | /> | 聽 | />
apply function to value | 聽 or聽 |> | 聽 |
聽 | 聽 | 聽 | 聽
Functor | 聽 | 聽 | 聽
map | or <<| | 聽 | <$> or fmap
same as map but arguments interchanged | |>> | 聽 | 聽
聽 | 聽 | 聽 | 聽
Monoid | 聽 | 聽 | 聽
monoid zero element | getZero() | mempty | mempty
append | ++ or plus | mappend | mappend
聽 | 聽 | 聽 | 聽
Applicative functors | 聽 | 聽 | 聽
apply (combine) | <> | 聽 | <>
Sequence actions, discarding the value of the first argument. | > | 聽 | *>
Sequence actions, discarding the value of the second argument. | < | 聽 | <*
A variant of聽<*>聽with the arguments reversed. | <> | 聽 | <>
Lift a value. | result | 聽 | pure
聽 | 聽 | 聽 | 聽
Alternative | 聽 | 聽 | 聽
alternatives: binary operation | <|> | 聽 | <|>
聽 | 聽 | 聽 | 聽
Monad | 聽 | 聽 | 聽
Bind Sequentially compose two actions, passing any value produced by the first as an argument to the second. | >>= | 聽 | >>=
Same as聽>>=, but with the arguments interchanged. | =<< | 聽 | =<<
?
Then we could perhaps write what can and cannot be done in f# compared to Haskell
@wallymathieu @ShalokShalom feel free to send a PR regarding this, whoever takes the initiative (including myself) just send a message first to avoid duplicate efforts.
My feeling is that we should add that table and regarding the sample files there are actually two files. One is too short, the other one is too long.
The long one, is in the Samples From FsControl folder, which at the same time came from an old exploratory project, originally in google code but now it's being imported to github by some devs, see this import and also this other import, with the translation table used at that time.
Now regarding the Learn you a Haskell file, that was an exercise @vstastny did to learn about the typeclassy stuff here, following the original haskell tutorial, and he gently contributed back to this repo. But note that it's not using the Haskell compatibility, because the idea I think, was to apply the same concepts in F#. So I think it worths adding to the doc, but maybe not in the compatibility (although it might be linked). One thing is syntax and another is abstractions.
I adore this table.
Then we could perhaps write what can and cannot be done in f# compared to Haskell
Yes, absolutely.
The easiest way to get the table into the docs could be to use github wiki ? Then we could start collaborate on it as well.
Since it does not contain any code examples, it's perhaps not so much a good fit for literate style of programming with fsx, or what's your thougts @gusty ?
The easiest way to get the table into the docs could be to use github wiki ?
I don't get it, what's complicated? You can put it directly in the docs, they support markdown directly AFAIK.
It doesn't support the same markdown syntax. It's a minor thing: you need to transform the table to the dialect of markdown that fsharp formatting supports.
Shame, but moving that out of the docs for a technical limitation seems hacky,
Is there any other way? Something like linking to an external site, as I did for the PlantUML diagram?
It's a minor thing: you need to transform the table to the dialect of markdown that fsharp formatting supports.
Actually this might be the easiest solution. What do you think?
Indeed.
The question is mostly what kind of markdown tables fsharp formatting supports?
https://github.com/fsprojects/FSharp.Formatting/issues/7 and see the linked examples.
Nice!
Very nice to see, that something such (comparable) trivial gets immediately implemented, while the whole range of the .NET world is still in chaos for such things: https://github.com/dotnet/docs/issues/3446
So perhaps someone wants to do a small pull request :wink:
Cool !
I found some inaccuracies, here's the corrected version
Also I noticed some issues.
Why don't we use (/=) directly? I don't remember if there was an issue, it was many years ago, maybe the F# parser at that time rejected it.
(++) should be redefined in the Haskell compatibility. I probably forgot to add it.
OK, i did some changes to this, lets see how they appeal you:
https://gist.github.com/ShalokShalom/11cf9b1943d36ac51939e83bb0fced84
Some questions:
I suggest creating an issue for each operator, which is unported.
We can then link to this specific issue from our comparison table.
Some operators still seem to be unnamed yet: What is the purpose?
I've started using <| sort of the same way I use it in Haskell. Since I'm not very deep into it, it's kind of helpful to have something where it's explained.
Not all operators are representable in F#, we can create issues, but the right place to create them will be in the F# compiler project, because there's nothing we can do about it here.
Regarding $ it's a bit for completeness there, but actually the main purpose of the operator which is to avoid parens, it's defeated since it doesn't have the same associativity as in Haskell. Again, there's nothing we can do about it.
Some operators still seem to be unnamed yet: What is the purpose?
Which one, for example?
I've started using <| sort of the s ...
Yes, I use it from time to time, but it also has not the same associativity, so for piping expressions it doesn't work, it's better to do the F# way, I mean reverse the pipe and write with the |> in those cases.
Mmm, indeed. What is your thoughts about the Ocaml way of doing things? More module oriented instead of type class oriented.
I don't have any experience in OCaml, but it seems to be more module oriented.
AFAIK they use their "functor" feature, which is not the same as the functor abstraction, it's rather a parametrizable module and they don't have typeclasses, but I read somewhere that both techniques are equivalent.
OCaml is very module oriented since they allow higher-order polymorphism by higher-order modules and yes, you can implement type classes as such ones.
Ah, I got now that I can use <| in order to substitute the $ in Standard F-Sharp.
Which one, for example?
=, <| and <> are without description currently and apply function to a value is without operators.
If there are no equivalents on one side or the other, can we mention it by something like not available
Otherwise is it questionable, if the list is either incomplete or the operator missing.
Some other questions:
pure' is correct? Since I do not find it in the source code.
And if binary operation is available in both F-Sharp and Haskell, why implement one in F-Sharp Plus?
Do they work differently?
Oh, then Github's search does probably crash with `
Thanks a lot
apply function to a value </ or |> has gotten dropped
So we can remove it?
Or mention not available
It's very common in f# code, so if it's not available in Haskell then I would find it useful have that fact in the table.
I don't remember why I added for Haskell.
See now: https://gist.github.com/ShalokShalom/11cf9b1943d36ac51939e83bb0fced84
So, how can I see the specific result of this table?
How does it look like in real life?
Since I like to adjust the visual appearance.
I hope its fine, that I actually named this project?
F#+ Haskell Compatibility burst the width of the column, so I think this can make it leaner and also give the project some identity. :)
apply function to a value or |> has gotten dropped
Yes, the definitions are 3 rows above.
And if binary operation is available in both F-Sharp and Haskell, why implement one in F-Sharp Plus?
Do they work differently?
Not 100% sure what do you mean.
Regarding to <|> it's simply the same operator in Haskell and FSharpPlus and also in other languages, like purescript, Idris if I'm not wrong.
I don't remember why I added for Haskell.
That's confusing, probably it was added by me in the original project. The thing is that in Haskell you can partially apply an operator on both sides, well I found out that by using those operators you achieve more or less the same effect but at the cost of ending up with combination of operators. Here's an example:
let f x = fun n -> n - x
in Haskell you can write it:
let f x = (- x)
here you can write:
let f x = (-)/> x
But in fact the idea of these operators is to be able to transform a function in an operator:
let sum x y = x + y
let a = x </sum/> y
@ShalokShalom you can start adding it to the docs, then after running Build or just building the docs you'll see how FSharp Formatting renders that table.
Oh, I see. I thought initially, this table is just to point out the compatibility layer itself.
So, in that case, a huge load of operators is missing?
What will we include and what not?
But in fact the idea of these operators is to be able to transform a function in an operator:
let sum x y = x + y
let a = x </sum/> y
I think we should point this out on its own. Otherwise, the whole sense would get gone.
Definitely.
What should get included and what not?
I would say, let's get it done with the basic stuff, as we have it for example.
The goal of the Haskell compatibility module is to facilitate translating code from Haskell, including running on-off examples, but normally if you translate something that later will become more important we should remove the Haskell compatibility. A good example of this, is the recent @wallymathieu work with Validations, see for example that inflexion point happening here
if you translate something that later will become more important we should remove the Haskell compatibility
So, a Haskell compatibility source-to-source converter onto F-Sharp would be reasonable?
To do this automaticly?
It will never be possible to fully emulate Haskell, specially because of the lazyness and the different type system. Still, my experience is that Haskell.Compatibility helps to run Haskell examples or to do the initial steps to port code coming from Haskell.
Still, human touch will always be required.
I mean Haskell Compatibility into native F-Sharp (Plus)
Oh, I see what you mean. I guess it makes sense, at least what we can do is to provide a brief guideline of what are the steps to take, and which decisions have to be made.
Yes, since this seems to be a simple find-and-replace, this might be a nice project for me as a newbie. :)
Go ahead if want to try it on your own, experiment a bit with it, then we can decide to keep it as a separate project/snippet or to include it in this lib.
The current upload looks like we could use another file extension, in order to achieve another syntax highlight?
I see that the table looks quite similar to here, is there a specific reason to use such one?
Is this purely to cooperate without any document editor?
I think it's because it was in code formatting.
But I just tried to remove the code and it's completely broken now.
I don't know what's wrong or what's the expected format, will keep trying.
Do you consider that this is an issue in F-Sharp Formatting itself?
Well, I guess they can help, so maybe an issue there would be sane?
Do you consider that this is an issue in F-Sharp Formatting itself?
Yes, definitely.
Well, I guess they can help, so maybe an issue there would be sane?
I think opened some issues there and they never came back. But please go ahead.
It seems to be working, the table is being generated but the style is missing. The tables reference a style header even and odd but they are not in .css they provide.
I'll keep looking ...
See for example this search https://github.com/fsprojects/FSharp.Formatting/search?utf8=%E2%9C%93&q=odd&type=
They generate that style, but they don't provide it.
Alternatively if someone knows of some nice styles for these tables please include it in our template file: https://github.com/gusty/FSharpPlus/blob/master/docsrc/tools/templates/template.cshtml
that kind of styling of tables is kind of common, so they probably assume that you will bring your own
Well, apart from that there definitely bugs in their parser, see below:
Generating 'D:\temp\989e43d\docsrc\tools\..\content/abstractions.html' Generating
'D:\temp\989e43d\docsrc\tools\..\content/applicative-functors.html' Generating
'D:\temp\989e43d\docsrc\tools\..\content/computation-expressions.html' Generating
'D:\temp\989e43d\docsrc\tools\..\content/generic-doc.html' Generating 'D:\temp\989e43d\docsrc\tools\..\content/haskell-compatibility.html' FsiEvaluationException: Error:
System.Exception: Unexpectedly stopped! [""; " |>>"; ""] at
[email protected](String message) in
c:\Tomas\Public\tpetricek\FSharp.Formatting\src\FSharp.Markdown\MarkdownParser.fs:line 756
at [email protected](Unit unitVar) in c:\Tomas\Public\tpetricek\FSharp.Formatting\src\FSharp.Markdown\MarkdownParser.fs:line 756
at [email protected](Unit unitVar0)
at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source)
at Microsoft.FSharp.Primitives.Basics.List.mapToFreshConsTail[a,b](FSharpList`1 cons, FSharpFunc`2 f, FSharpList`1 x)
at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x)
at Microsoft.FSharp.Collections.ListModule.Map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 list) at Microsoft.FSharp.Primitives.Basics.List.mapToFreshConsTail[a,b](FSharpList`1 cons, FSharpFunc`2 f, FSharpList`1 x)
at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x)
at [email protected](Unit unitVar) in c:\Tomas\Public\tpetricek\FSharp.Formatting\src\FSharp.Markdown\MarkdownParser.fs:line 690
at [email protected](Unit unitVar0)
at [email protected](Unit unitVar0)
at [email protected](Unit unitVar0)
at Microsoft.FSharp.Collections.Generator.Microsoft-FSharp-Collections-Generator-Generator-1-get_Apply@435.Invoke(Unit unitVar0)
at Microsoft.FSharp.Collections.Generator.appG[a](Generator`1 g)
Had to leave the table as code for now.
If someone want to report these errors, please go ahead !
Sounds like this is pretty much unmaintained?
Is there any alternative to FSharp Format?
No that I know. But it's just a matter of making some noise and either they come back or eventually a new maintainer will be assigned.
Coming back to the very beginning of our conversation, I would consider now the alternative @wallymathieu proposed initially: linking to a normal .md file, embedding it, or make it open in a new window.
And what speaks against something like this?

That looks very nice, but the problem is that it's hard to maintain.
I mean, you have to generate it each time you update it.
I had the same problem with the plantUml diagram, but finally I found a solution that generates it in the build process.
Anyway, we can also create it in plain html, right?
Indeed, plain html is simple enough 馃憤 so could be an alternative
Generate it?
Its a simple screenshot. I edit the parts that I want, go fullscreen and: Screenie :D
Does this list change so often that a difference of some seconds makes such a huge difference?
Well, you always want someone who is totally unfamiliar with things to be able to edit it
Yeah, a spreadsheet?
So can we create an issue on formatting? We can ping forki if we are willing to help out on any fsproject stuff.
So, I think I got a great idea, while it might sound a little bit crazy first.
Its completely optional, so you can do both.
I just realised, that Wikipedia shows such tables in a neat way and I think its nice to link from the top page
( http://gusty.github.io/FSharpPlus/ ) to the Wikipedia article.
In general is Wikipedia a great place for such docs, IMHO since a lot of people will inform themself their about fsharp. So if we create a own, dedicated F-Sharp Plus page, which reflects the major aspects of the homepage can we link to it from the F-Sharp article. So, many people will get aware about the project in general and we can store the table there. Plus, such documentation in the form of examples are quite common in programming article on Wikipedia. See here: https://en.wikipedia.org/wiki/Map_(higher-order_function)
I haven't seen a wikipedia article about a specific library, but if you wan't to try adding one, go ahead.
It might be the first :)
Well, F-Sharp Plus is more as a library ;)
Its a couple of libraries in one ;)
So you can say its a library collection?
It's true that is not a specific library, it's rather a base library, or even as @wallymathieu said, a language extension.
Language extension sounds awesome, this is also what I thought first.
We are also able to put it simply in Github?
https://github.com/ipfs/ipfs/blob/master/IMPLEMENTATION_STATUS.md
Yes, that's the option discussed at the beginning, Linking to an md file.
Apples and Lemons convinced me. I think we all should code in fruits. Also an option for applicative operators. ;)
Do you think its sane to name this library Hashkell or H#? 馃槃
No way, that's not the goal of this library.
This is meant to be a base library for F#, the fact that it uses some concepts from Haskell doesn't convert it in a Haskell emulator and that's not the purpose of this project.
Moreover, I was thinking many times in removing the Haskell compatibility and make it a separate project, but the idea of the Compatibility namespace is to have other languages.
Taking ideas from Haskell is common practice today, and you see it in most frameworks, libraries and languages.
Having it as a separate library sounds nice 馃憤 It also promotes the idea of F#+ base library status (if you have an eco system of libraries with distinct and sensible responsibilities).
@gusty
I was thinking many times in removing the Haskell compatibility and make it a separate project, but the idea of the Compatibility namespace is to have other languages.
Is there any chance to get OCaml support in?
@wallymathieu True, that was also my conclusion. Actually there is in fsprojects already a Compatibility project which has a Haskell module but there's almost nothing there.
That might be a good destination for the Haskell Compatibility. Feel free to open an issue to further discuss it.
@ShalokShalom regarding OCaml in that library there is some support already.
Oh, fine ^-^
On the emoji for indicators I've always felt that I should be able to make emoji as operators, but F# throws up every time I try. By contrast I can use them as variables or types without issue.
type ``馃尠`` = string
let ``馃崗`` = true
let ``馃崊`` = false
//the best workaround I can think of is to use off menu butterfly operator
let ``馃崝`` a b = a * b
3 |>``馃崝``<| 4
//or ....
type System.Int32 with
member x.``馃檯`` n = x * n
3 .``馃檯`` 5
WHEN WILL THE CHAINS THAT BIND OUR OPERATORS BE LOOSED.
This way >> https://github.com/fsharp/fslang-design :D
Perl users will scream from feelings of jealousy and fascination ;)
I've already tried, Don won't hear my pleas of mercy.
I'm closing this issue since Haskell compatibility has been ported to FSharp.Compatibility : https://github.com/fsprojects/FSharp.Compatibility/pull/11 including the table.
Most helpful comment
On the emoji for indicators I've always felt that I should be able to make emoji as operators, but F# throws up every time I try. By contrast I can use them as variables or types without issue.
WHEN WILL THE CHAINS THAT BIND OUR OPERATORS BE LOOSED.