[Haskell-beginners] How to nest arbitrary things

martin martin.drautzburg at web.de
Mon Dec 21 19:41:47 UTC 2015


Am 12/21/2015 um 06:30 PM schrieb Francesco Ariis:
> On Mon, Dec 21, 2015 at 06:00:06PM +0100, martin wrote:
>> That's fine. I'm happy not to be able to pack a truck into another truck.
>> Only problem is that I don't know how to write an "unpack" function,
>> which removes one level of nesting. I can only write unpackTruck,
>> unpackParcel ...
>>
>> I suppose the ability to write a generic unpack function implies that
>> there can be a generic pack function and then I could pack a truck into
>> another truck.
> 
> I would say typeclasses might help you, but before that, what would
> the unpack function signature look like?
> 
>     unpack :: (Package s) => s a -> [a]
> 
> Like this? If so, I don't see much benefit (or what problem we're
> trying to solve) in trucks>boxes>parcels>cans types.

Unpacking should separate the container from its contents, i.e. given a packed container it should return an empty
container and whatever was inside.



More information about the Beginners mailing list