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?
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.
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.
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’
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With