Coming from elm to haskell

First impressions…
Surprised finding so much similar things in haskell and elm.
On the other hand, annoyed about some differences
Example functions for integer divisions
in Elm 7 // 3 == 2 missing in Haskell, in Haskell divide 7 3 missing in Elm
floor (7 / 3) same in Elm and Haskell
I was translating one of my elm programs to haskell, namely the function of Julian Date JDN calculated from the given date. See my elm code function jdnGr

I should add lots of parentheses changing all ( x // y ) in elm to (divide x y) in haskell
Well, I found just a haskell package containing julian date in the date.time library.
Next I should learn, how to use it as imported to my code.

I like a lot haskell utility ghci with handy features, elm repl is comparable tool.
I miss anyway in haskell a dev tool similar to elm reactor.

2 Likes

If you miss some operator you’re used to, you can always declare it yourself:

(//) :: Integral a => a -> a -> a
(//) = div
infixl 7  //

you can also use functions infix, like

7 `div` 3 == div 7 3

Note that if not explicitly declared, infix-used functions have fixity 9. Luckily, in GHC.Real, we have the following fixity declaration:

infixl 7  /, `quot`, `rem`, `div`, `mod`
4 Likes

Here is my very first haskell module and the main which calculate Julian Day Number (needed in many astronomical calculations).

I have declared there operator ‘//’ with infixl.

I don’t understand the meaning of the number 7 argument of infixl, just realised only that changing the value too low will show incorrect result values.

There’s a good explanation in this section of an archive of Stack Overflow documentation.

1 Like

Yes, really well explained the binding precedence of operators vs functions.
Wise use of infixes can reduce parentheses.