## Kotlin: How to show an instance’s data type (class) in the REPL

If you need to see the data type (or class) of an instance in the Kotlin REPL, you can use the `javaClass`

method to see that type. Here are a few examples:

By Alvin Alexander. Last updated: August 9 2018

If you need to see the data type (or class) of an instance in the Kotlin REPL, you can use the `javaClass`

method to see that type. Here are a few examples:

By Alvin Alexander. Last updated: June 15 2018

Taken from shapeless' README:

Shapeless is a type class and dependent type based generic programming library for Scala.

To me, Shapeless is a toolkit to leverage Scala's type system at your own profit. You may use it to have more "precise" types, like statically sized list (lists which size is known at compile time), you may also use HList as a better tuple.

More generally, Shapeless can be used to make the compiler work for you, scrape some boilerplate, and gain a little extra typesafety.

By Alvin Alexander. Last updated: June 16 2017

“Two steps are required to write a good piece of code. The first step is to get the algorithm right. The second step is to figure out which sorts of things (types) it works for.”

From the “Deriving a Generic Algorithm” chapter in the book, From Mathematics to Generic Programming.

By Alvin Alexander. Last updated: May 11 2018

Java FAQ: What are the *rules* about Java arithmetic (multiplication, division) involving mixed data types?

While working on a math problem in Java just a little while ago, I realized that I wasn’t comfortable with the Java mixed-type division rules. That is, I wondered if the result of this equation:

3 / 2

the same as the result of this equation:

3 / 2.0

or this equation:

3.0 / 2.0

By Alvin Alexander. Last updated: March 20 2017

If you need to have multiple types extend a base type in Haskell, while using the `data`

keyword, and while using Haskell’s *record syntax*, this approach seems to work:

By Alvin Alexander. Last updated: July 16 2019

Scala FAQ: What are the Scala *numeric data types*? How many bits do they use to store their data, and what is the range of those data types?

Courtesy of the excellent book, Programming in Scala, here is a list and description of the Scala data types, including bit sizes and data ranges:

Data TypeDefinitionBoolean true or false Byte 8-bit signed two's complement integer (-2^7 to 2^7-1, inclusive) -128 to 127 Short 16-bit signed two's complement integer (-2^15 to 2^15-1, inclusive) 32,768 to 32,767 Int 32-bit two's complement integer (-2^31 to 2^31-1, inclusive) 2,147,483,648 to 2,147,483,647 Long 64-bit two's complement integer (-2^63 to 2^63-1, inclusive) -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 Float 32-bit IEEE 754 single-precision float 1.40129846432481707e-45 to 3.40282346638528860e+38 (positive or negative) Double 64-bit IEEE 754 double-precision float 4.94065645841246544e-324d to 1.79769313486231570e+308d (positive or negative) Char 16-bit unsigned Unicode character (0 to 2^16-1, inclusive) 0 to 65,535 String a sequence of Chars