Let's say I have a type MyType defined in module My.Module. I want to have the String "My.Module.MyType" (or something like that). If I just type the String directly, I might have a typo, and if the module or type name changes, I'd like to know at compile time.
Ah, there appears there might be confusion about what I'm asking. Please look at the question carefully. Given the code:
module My.Module
type MyType = Int
data MyType2 = MyConstructor2 Int
main = do
putStrLn $ theMagic MyType
putStrLn $ theMagic MyType2
The output I want is:
My.Module.MyType
My.Module.MyType2
I'm looking for the type name, not the type definition. typeOf would output Int and such, that's not what I want.
In Haskell it is also very easiest form of data type which can be used, easy to handle and create as well. String can be created by using double quotes (“”) inside this we can write our string or value that we want string type to be hold for us.
The most common I/O operations are defined in the System.IO library. For the most basic stdin/stdout Unix-style programs in Haskell, we can use the interact function: interact :: (String -> String) -> IO () This higher-order function takes, as an argument, some function for processing a string (of type String -> String).
1 Data declarations. One introduces, or declares, a type in Haskell via the data statement. In general a data declaration looks like: data [context =>] type tv1 ...
We'll examine their different use cases, and observe how to convert between them. The String type is the most basic form of representing strings in Haskell. It is a simple type synonym for a list of unicode characters (the Char type). So whenever you see [Char] in your compile errors, know this refers to the basic String type.
You can use a Proxy
for this:
Prelude> import Data.Typeable
Prelude Data.Typeable> show $ typeRep (Proxy :: Proxy [Int])
"[Int]"
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