Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Look up type synonyms in haskell

Tags:

haskell

ghci

Is there a way to look up what type synonyms actually mean? Is there perhaps some GHCi command that I can use to see if a given type is a synonym of something else?

like image 714
The Hoff Avatar asked Mar 12 '18 20:03

The Hoff


People also ask

What is a type synonym in Haskell?

From HaskellWiki. A type synonym is a new name for an existing type. Values of different synonyms of the same type are entirely compatible. In Haskell you can define a type synonym using type : type MyChar = Char.

What is data Haskell?

In Haskell, you can have many constructors for your data type, separated by a vertical bar | . Each of your constructors then has its own list of data types! So different constructors of the same type can have different underlying data! We refer to a type with multiple constructors as a “sum” type.


1 Answers

Yes, in GHCi you can use :info:

Prelude> :info String
type String = [Char]    -- Defined in ‘GHC.Base’
Prelude>

EDIT and more examples including a non-alias example:

Prelude> :info Rational
type Rational = GHC.Real.Ratio Integer  -- Defined in ‘GHC.Real’
Prelude> :i Double
data Double = GHC.Types.D# GHC.Prim.Double#
        -- Defined in ‘GHC.Types’
like image 68
Thomas M. DuBuisson Avatar answered Nov 10 '22 16:11

Thomas M. DuBuisson