I really donot know how to use `newtype` ?

import Control.Monad.State import Control.Monad.Reader data XConf = XConf {} data XState = XState {} newtype X a = X (ReaderT XConf (StateT XState IO) a)
:t StateT StateT :: (s -> m (a, s)) -> StateT s m a
:t ReaderT ReaderT :: (r -> m a) -> ReaderT r m a
then how to use `X` ? Would you mind explaining the newtype X in detail ? Sinerely! ----- fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/I-really-donot-know-how-to-use-%60newtype%60---tp26541... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

zaxis wrote:
then how to use `X` ? Would you mind explaining the newtype X in detail ?
You can just think of a newtype as a normal datatype:
data X a = X (ReaderT XConf (StateT XState IO) a)
I.e. construction and pattern matching work indentically. Every newtype you will find will have exactly one constructor with exactly one field. Only datatypes that have one constructor with one field can be made newtypes. You can only use generalized deriving on newtypes: http://www.haskell.org/ghc/docs/6.10-latest/html/users_guide/deriving.html There are some other differences between datatypes and newtypes which are only sometimes important. They are to do with efficiency and bottom. You can read about them here: http://www.haskell.org/tutorial/moretypes.html HTH, Martijn.
participants (2)
-
Martijn van Steenbergen
-
zaxis