Wolfram Kahl suggested to add functions isNullPtr and isNullFunPtr (with the expected semantics) to the Ptr module. Opinions? Manuel
Wolfram Kahl suggested to add functions isNullPtr and isNullFunPtr (with the expected semantics) to the Ptr module. Opinions?
Ptr and FunPtr are already instances of Eq, so which is easier to type? isNullPtr x or x==nullPtr So I don't see the motivation for the new predicates, but I don't have any objections either. Regards, Malcolm
Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> wrote,
Wolfram Kahl suggested to add functions isNullPtr and isNullFunPtr (with the expected semantics) to the Ptr module. Opinions?
Ptr and FunPtr are already instances of Eq, so which is easier to type? isNullPtr x or x==nullPtr
So I don't see the motivation for the new predicates, but I don't have any objections either.
Sure, but there is also null = (== []) in the Prelude and `Maybe.isNothing'. So, the reasoning for adding these two functions would be that Haskell has a tradition of providing predicates like this as alternatives to the explicit use of (==). Personally, I also don't care much in either direction. Any other opinions? Cheers, Manuel
Manuel M T Chakravarty <chak@cse.unsw.edu.au> writes:
Sure, but there is also null = (== []) in the Prelude and `Maybe.isNothing'.
No, the definition of null is null [] = True which is quite different from (==[]) because it has a less-constrained type. null :: [a] -> Bool (==[]) :: Eq a => [a] -> Bool Likewise, isNothing :: Maybe a -> Bool (==Nothing) :: Eq a => Maybe a -> Bool So there are good reasons for having separate predicates testing the null/empty case at those polymorphic types, but no reason (except consistency of naming) for a pseudo-polymorphic type like Ptr a. However, consistency of naming is perhaps sufficient reason to add them anyway. Regards, Malcolm
Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> wrote,
Manuel M T Chakravarty <chak@cse.unsw.edu.au> writes:
Sure, but there is also null = (== []) in the Prelude and `Maybe.isNothing'.
No, the definition of null is null [] = True which is quite different from (==[]) because it has a less-constrained type. null :: [a] -> Bool (==[]) :: Eq a => [a] -> Bool
Likewise, isNothing :: Maybe a -> Bool (==Nothing) :: Eq a => Maybe a -> Bool
So there are good reasons for having separate predicates testing the null/empty case at those polymorphic types, but no reason (except consistency of naming) for a pseudo-polymorphic type like Ptr a.
Oh, you are right. I overlooked this. In this case, I actually tend to not include these extra functions (unless somebody likes to argue in their favour). Cheers, Manuel
participants (2)
-
Malcolm Wallace -
Manuel M T Chakravarty