Re: [Haskell-cafe] a way to convert partial functions to functions with Maybe's

2010-04-14 Thread Ozgur Akgun
Oh well, thanks for all the response.

I have a module with lots of one line function definitons, and they just
*look* ugly when I wrap the return type with Maybe. This is a
straightforward, and trivial job (the conversion) and I really don't care
about other problems (such as non-termination plus some other conditions)
for the time being.

I am not attampting to remove Maybe completely, don't worry :)
I quite like it, and use it in most places. But now always apparently.

Best,

On 14 April 2010 08:50, Roel van Dijk  wrote:

> On Wed, Apr 14, 2010 at 2:32 AM, Ivan Miljenovic
>  wrote:
> > Why not use Maybe for func1 in the first place?  Or are you wanting to
> > automagically make all uses of head, tail, etc. safe?
>
> In which case there is already the 'safe' package:
> http://hackage.haskell.org/package/safe
>



-- 
Ozgur Akgun
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] a way to convert partial functions to functions with Maybe's

2010-04-14 Thread Roel van Dijk
On Wed, Apr 14, 2010 at 2:32 AM, Ivan Miljenovic
 wrote:
> Why not use Maybe for func1 in the first place?  Or are you wanting to
> automagically make all uses of head, tail, etc. safe?

In which case there is already the 'safe' package:
http://hackage.haskell.org/package/safe
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] a way to convert partial functions to functions with Maybe's

2010-04-13 Thread Ivan Miljenovic
On 13 April 2010 20:02, Ozgur Akgun  wrote:
> func1 :: T -> T
> func1 A = B
>
> func1Fixed :: T -> Maybe T
> func1Fixed A = Just B
> func1Fixed _ = Nothing

Why not use Maybe for func1 in the first place?  Or are you wanting to
automagically make all uses of head, tail, etc. safe?


-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] a way to convert partial functions to functions with Maybe's

2010-04-13 Thread Daniel Schoepe
Excerpts from Ozgur Akgun's message of Tue Apr 13 12:02:06 +0200 2010:
> Cafe,
> 
> Is there a way (without going into the IO lands) to achieve this:
> [..]

There's package for that on hackage:
http://hackage.haskell.org/packages/archive/spoon/0.3/doc/html/Control-Spoon.html

However, this is somewhat controversial regarding _|_:
http://www.reddit.com/r/haskell/comments/acasn/tired_of_functions_that_could_live_in_maybe_but/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] a way to convert partial functions to functions with Maybe's

2010-04-13 Thread Ozgur Akgun
Cafe,

Is there a way (without going into the IO lands) to achieve this:

data T = A | B | C

func1 :: T -> T
func1 A = B

func1Fixed :: T -> Maybe T
func1Fixed A = Just B
func1Fixed _ = Nothing

I want a function to generate func1Fixed, given func1.

I guess this is doable with exception handling (catching the error from
func1)? Is it the only way?

Best,

-- 
Ozgur Akgun
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe