[Haskell-cafe] newtype and access control
Steven Leiva
leiva.steven at gmail.com
Sun Oct 29 23:52:31 UTC 2017
Hello everyone,
I am watching a talk on YouTube calledWrangling Monad Transformer Stacks.
The talk has the following code:
code{-# LANGUAGE GeneralizedNewtypeDeriving -#}
module DBTrans where
newtype WithTrans a = WithTrans (WithDBConn a) deriving (Functor, Applicative,
Monad)
inDBTrans :: WithTrans a -> WithConn a
inDBTrans = ...
NOT USING MIXMAX YET?
The speaker mentions that by using a newtype, we can perform "access control".
The functioninDBTrans is "aware" that the type constructorWithTrans is simply a
wrapper forWithDBConn, 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 forinDBTrans 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 toinDBTrans can do access control.
Thank you for any help!
Steven Leiva
305.528.6038
leiva.steven at gmail.com
http://www.linkedin.com/in/stevenleiva
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20171029/5d30153c/attachment.html>
More information about the Haskell-Cafe
mailing list