Is there anything wrong with wrapping Data.Sequence in my own Queue type?

Viewed 126

I want a queue for my application. From what I've read, Data.Sequence is the best option for production code. In order to keep my code elegant, idiomatic, and overall Haskelly, is there anything wrong with wrapping Data.Sequence up in my own Queue data type in order to hide the functionality I don't need?

1 Answers

Nothing wrong at all - in fact, that's precisely what newtype is for!

Ideally, your types should reflect your intentions - whoever reads your code (including yourself, in the future, when you have forgotten what you did and why) should be able to tell what a type is for

So, even if your queue is merely a Sequence, wrapping it into your own Queue newtype will tell the (human) readers "this particular sequence is to be used for queuing" - besides the benefits of hiding non-required functionality, and preventing mixing up your values (i.e. no accidentally passing another Sequence that is not supposed to be a queue to a function that expects a queue).

Related