In describing NegativeLiterals, Haskell provides an example of how using a language extension can change the performance of some code, and then says
Other examples may actually change behavior, and not just be less effective.
After cheating with the extension a bit, I could not find any of these cases of behavior changes. I could only find the performance changes that they were talking about, and several programs that would have an error with and without the extension.
What are these programs that change their behavior when the NegativeLiterals extension is enabled?
, , fromInteger fromInteger, . fromInteger . negate negate . fromInteger. , , - - , .
fromInteger
fromInteger . negate
negate . fromInteger
, :
data Bad = Bad Integer deriving (Show) instance Num Bad where negate (Bad a) = Bad (a + 1) fromInteger = Bad
:
*Main> (-1) :: Bad Bad 2 *Main> :set -XNegativeLiterals *Main> (-1) :: Bad Bad (-1) *Main>
, Int8 from Data.Int. , 8. -128 127. , -128 128 Int8, , . NegativeLiterals -128 Int8, .
Int8
Data.Int
8
-128
128
NegativeLiterals
, ghci 128 , -128 , -128 . , , Int8 , , .
ghci
NegativeLiteralsalso changes the way you analyze some expressions. Unary is -interpreted as an operator with the same priority as binary -(i.e. 6), but with NegativeLiteralsa -that is, directly (without a space), followed by a number, will be part of the literal. Here is an example of how this can make a difference:
-
>>> :set -XNoNegativeLiterals >>> -1 'mod' 2 -1 >>> :set -XNegativeLiterals >>> -1 'mod' 2 1 >>> - 1 'mod' 2 -1
I got this from this StackOverflow question.
Source: https://habr.com/ru/post/1692225/More articles:Интеграция приложений AngularJS с Google Analytics - javascriptWhy the loops in the built-in function cannot be auto-vectorized correctly? - c ++Name for function with signature: `(a → a → b) → (a → b)` - functional-programmingAngularJS with Google Analytics - angularjshttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1692224/leiningen-raises-tried-to-use-insecure-http-repository-without-tls-but-for-which-dependency&usg=ALkJrhi2c0_kaexhk93UyKg5syjdC_tgQQCreate a hole in the interactive webview for touch events - react-nativeFix Symfony 3.4 Deprecated PHPUnit Warnings - phpЗамените значение в столбце с помощью vlookup другого фрейма данных, только если это значение существует - pythonНадлежащая структура для многомодульных модулей Gradle с IntelliJ IDEA - intellij-ideaHow to handle environment variables in a deployed SF4 application - symfonyAll Articles