3 ms·
I'll bat my eyelids, but only after I kick myself ;-P If you're up for a game of No True Scotsman, can you name me a statically typed language that does the sa
by MaxBarraclough 6y ago
I'll bat my eyelids, but only after I kick myself ;-P
If you're up for a game of No True Scotsman, can you name me a statically typed language that does the same?
- recursive 6y agoVisual basic
- MaxBarraclough 6y agoI don't think so. According to this, in Visual Basic, the '/' operator isn't defined for integer types. https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/data-types-of-operator-results#floating-point-arithmetic https://docs.microsoft.com/en-us/dotnet/visual-basic/languag...
- recursive 6y agoIntegers are right there in the table on the page you're linking to. If you don't believe me, perhaps you'll believe output from the machine. https://tio.run/##K0vSTc4vSv3/3zc/pTQnVcEjNScnn4szuDRJwTcxM09Dk4uTMyUzVyFPIbFYITOvJDU9tUjBVsHQACqegipuAhR2zs8rzs9J1QsvyixJ9cnMS9UwNFDQVzABGuWal6IANJoLREMs/P8fAA https://tio.run/##K0vSTc4vSv3/3zc/pTQnVcEjNScnn4szuDRJwTcxM0... * edited for guideline compliance
- MaxBarraclough 6y agoLooks like you're right. In my defense the page I linked states that The / operator is defined only for the Decimal, Single, and Double data types. I suppose it accepts integer types by means of 'widening'? > Did you read it? The HN guidelines ask that you don't do that.
- recursive 6y agoI've edited my comment for guideline compliance. I don't think it settles anything, but a trivial function that divides two integers and returns the result compiles to this: IL_0000: ldarg.1 IL_0001: conv.r8 IL_0002: ldarg.2 IL_0003: conv.r8 IL_0004: div IL_0005: ret conv.r8 is an explicit conversion to double precision float in the target language, MSIL.
- MaxBarraclough 6y agoI was already convinced by your earlier tio.run example, but I'm still a bit baffled by the page saying The / operator is defined only for the Decimal, Single, and Double data types.
- 1wd 6y agoNim https://play.nim-lang.org/#ix=2zbk https://play.nim-lang.org/#ix=2zbk
- MaxBarraclough 6y agoInteresting, thanks. I see Nim uses '/%' for integer division. [0] I can't say I like that decision. [0] https://nim-lang.org/docs/manual.html#types-preminusdefined-integer-types https://nim-lang.org/docs/manual.html#types-preminusdefined-...
- dom96 6y agoUnsigned integer division. In practice I haven’t seen this operator used anywhere yet.
- Smaug123 6y agoHave I gone mad? (EDIT: it appears I have.) ``` GHCi, version 8.6.5: http://www.haskell.org/ghc/ http://www.haskell.org/ghc/ :? for help Prelude> 1 / 2 0.5 ``` This is because 1 and 2 are polymorphic and get instantiated to floats here. Witchcraft.
- MaxBarraclough 6y agoI think you're still right though. I know Haskell has an unusual approach to numbers, but it looks like the resultant type is indeed different from the type of the operands. I got this from typeOf (/): Note: there are several potential instances: instance RealFloat a => Fractional (Complex a) -- Defined in ‘Data.Complex’ instance HasResolution a => Fractional (Data.Fixed.Fixed a) -- Defined in ‘Data.Fixed’ instance Integral a => Fractional (Ratio a) -- Defined in ‘GHC.Real’ ...plus two others
- nybble41 6y agoThere are many instances for Fractional, but the resultant type of the (/) operator is always the same as the operands: GHCI> :i (/) class Num a => Fractional a where (/) :: a -> a -> a ... -- Defined in ‘GHC.Real’ infixl 7 / The key is that integer types aren't Fractional, so the Haskell 2010 defaulting rules[1] cause the literals to be interpreted as Double. With an appropriate default declaration GHC could have picked Ratio Integer, Complex Double, etc. instead, but without one Integer and Double are the only options and Integer wouldn't satisfy the constraints. [1] https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-750004.3 https://www.haskell.org/onlinereport/haskell2010/haskellch4....
- e12e 6y agoJulia? There's an integer division operator, but the default is... More complex: https://docs.julialang.org/en/v1/manual/integers-and-floating-point-numbers/ https://docs.julialang.org/en/v1/manual/integers-and-floatin...