On Fri, Feb 6, 2009 at 1:00 PM, Antoine Latter <aslat...@gmail.com> wrote:
> Tangential to all of this - sometimes my unsafeXXX functions are pure,
> but partial.  So I'll have:
>
> foo :: a -> b -> Maybe c
>
> and
>
> unsafeFoo :: a -> b -> c

I use the "unsafe" prefix in the same way. For me it means 'assume
that preconditions hold'. If the preconditions do not hold and you
evaluate an unsafe function anyway I would expect an error, as opposed
to an exception. I have done that in my (tiny) roman numerals package.

-- simplified
toRoman :: Int -> Either String Int
unsafeToRoman :: Int -> String

The first function is very clear about the fact that something can go
wrong. If you provide it with a value of (-3) it will (hopefully)
produce something like 'Left "no negative numbers allowed"'. The
second function hides this fact and will result in a (uncatchable)
runtime error. It is still a pure function, but preventing errors is
now the responsibility of whoever evaluates it.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to