Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between Const and Constant?

Tags:

haskell

There seems to be two implementations of the constant functor:

  • Const in Control.Applicative

  • Constant in Data.Functor.Constant

Why do both of them exist, and which one should I use?

like image 810
Lambda Fairy Avatar asked Aug 26 '15 09:08

Lambda Fairy


People also ask

What is the difference between a constant and a variable?

A constant is a data type that substitutes a literal. Constants are useful in situations where a specific, unchanging value is to be used at various times during the software program A variable in a program can change its value during the course of execution of the program. A constant retains the same value throughout the program.

What is a constant in science?

What is a Constant? These are values that do not change during experiments. For example, in an experiment where one wants to test how the growth of plants is affected by the amount of water, factors like type of soil, temperature, type of plant and sunlight all stay the same in the course of the experiment.

What is the difference between define and const in C?

Difference between #define and const in C? #define is a preprocessor directive. Data defined by the #define macro definition are preprocessed, so that your entire code can use it. This can free up space and increase compilation times.

Why do we use const instead of regular variable?

This means we can typecast, move addresses, and everything else you’d be able to do with a regular variable besides change the data itself, since the data assigned to that variable is constant. In general, const is a better option if we have a choice and it can successfully apply to the code.


1 Answers

They do the same thing indeed. As far as I'm aware of, most people use Const because it is older (as Bakuriu pointed out), is in base and has a shorter name. Case in point: lens uses Const. There was at least one discussion about unifying them in the libraries mailing list back in 2012, but it didn't went through, seemingly because of differences of opinion about the name and the most appropriate module for it.

like image 54
duplode Avatar answered Oct 06 '22 20:10

duplode