Changes to Typeable

Tyson Whitehead twhitehead at gmail.com
Thu Oct 4 22:58:43 CEST 2012


On October 4, 2012 13:48:42 Ben Millwood wrote:
> On Thu, Oct 4, 2012 at 5:03 PM, Tyson Whitehead <twhitehead at gmail.com>
> > import Data.Typeable
> > import Data.Maybe
> > 
> > magic :: Typeable a => a -> a
> > magic x =
> > 
> >   case cast x of
> >   
> >     Just x -> cast $ fromJust $ x ++ " (ta da)"
> >     _  -> x
> > 
> > gives you id except for strings.
> 
> ITYM fromJust $ cast rather than the other way around. But the ability
> to cast like this does not give you access to data structure you
> didn't already have – it does not violate abstraction.

Indeed.  I did mean those to be swapped.  Thanks for picking up on that.

I have to confess though, I'm not really following on how this doesn't give 
you access to data structure you didn't already have?  Perhaps we are not 
thinking of the same thing when you say "access to data structure"?

Doesn't the above "a -> a" function (under the proposed system where you don't 
need a "Typeable a" constraint") take apart some of its argument

magic 1 ---> 1
magic 2 ---> 2
magic "hello world" ---> "hello world (ta da)"

Doesn't this mean then that whole "theorems for free" stuff goes out the 
window?  Isn't its whole basis the idea that unconstrained types are actually 
statements that those arguments won't be constructed/deconstructed?

Thanks!  -Tyson



More information about the Libraries mailing list