Hello everyone,
I am watching a talk on YouTube called Wrangling Monad Transformer Stacks.
The talk has the following code:
{-# LANGUAGE GeneralizedNewtypeDeriving -#} module DBTrans where newtype WithTrans a = WithTrans (WithDBConn a) deriving (Functor, Applicative, Monad) inDBTrans :: WithTrans a -> WithConn a inDBTrans = ... |
|
The speaker mentions that by using a newtype, we can perform "access control". The function inDBTrans is "aware" that the type constructor WithTrans is simply a wrapper for WithDBConn, and that functions outside of the module are not privy to that information.
Out of necessity, the speaker has to assume a certain level of Haskell knowledge that I don't have, because I am confused as to what language principles would allow for inDBTrans to be used for access control.
I understand that a newtype declaration does create a new type from a "type safey" point of view; that a newtype declaration is required to have a single data constructor with a single (not named) field; and that, once the type-checking is done, the compiler can strip out the newtype wrapper and leave the underlying type (informally speaking, of course), but that still doesn't get me to inDBTrans can do access control.
Thank you for any help! |