[Haskell-beginners] Further constraining types

Brandon Allbery allbery.b at gmail.com
Thu Aug 4 07:23:48 CEST 2011


On Thu, Aug 4, 2011 at 01:03, Christopher Howard <
christopher.howard at frigidcode.com> wrote:

> ...to deal with the case where a negative parameter is passed in. But it
> seems like what I really want is something like this:
>
> f :: Positive Int -> Int
>
> I.e., the "positiveness" is hard-coded into the parameter type. But how
> do I do this? I was thinking it would involve some kind of "Positive
> Int" type, and some kind of "constructor" function like so:
>
> positiveNum :: Int -> Positive Int
>
> However, then this constructor function must deal with the problem of
> receiving a negative integer, and thus I have only shifted the problem.
> It is still an improvement, but yet it seems like I am missing some
> important concept here...
>

The concept is called "dependent types", where a type can depend on a value.
 Haskell doesn't support them natively, although there are some hacks for
limited cases.

-- 
brandon s allbery                                      allbery.b at gmail.com
wandering unix systems administrator (available)     (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110804/57e6e4cf/attachment.htm>


More information about the Beginners mailing list