|
![](/i/fill.gif) |
>> module Foobar (Foo (..), foobar) where
>>
>> data Foo = Foo Int deriving Show
>> data Bar = Bar Int deriving Show
>>
>> foobar :: Foo -> Bar
>> foobar (Foo x) = Bar x
>
> Correct me if I'm wrong, but apart from showing that the standard
> seemingly allows it, how would you use that in a real world scenario?
>
> By exporting foobar, you intend to use it somewhere else in your code,
> right? Which means there's another piece of code somewhere that expects
> to receive something of type bar, without knowing what type bar actually
> is!
>
> How does that work?
Well, you're right in that you cannot write any code which explicitly
expects Bar. You can pass the result to any function that works with
/all/ types, or any function that works with any showable type. If the
module exported some functions that expect Bar as input, you can pass
the result to them. But you can't write that in a type signature,
which... yeah, is a bit silly.
My point wasn't so much that this is a something anybody is likely to
want to do. My point was a counter-example to the "that's obviously
impossible" argument. It's /not/ impossible at all.
Post a reply to this message
|
![](/i/fill.gif) |