Re: [Haskell-cafe] Avoiding parametric function binding

2012-01-02 Thread Kevin Quick
On Sun, 01 Jan 2012 05:29:42 -0700, Sebastian Fischer wrote: On Sat, Dec 31, 2011 at 4:09 PM, Kevin Quick wrote: onVarElem :: forall a . (Show a) => (Maybe a -> String) -> Var -> String The problem is the scope of the quantification of the type variable 'a'. You can use higher-rank types

Re: [Haskell-cafe] Avoiding parametric function binding

2012-01-01 Thread Sebastian Fischer
On Sat, Dec 31, 2011 at 4:09 PM, Kevin Quick wrote: > > onVarElem :: forall a . (Show a) => (Maybe a -> String) -> Var -> String >> onVarElem f (V1 x) = f x >> onVarElem f (V2 x) = f x >> >> main = putStrLn . onVarElem elemStr $ test >> > > This is probably a better design, but still fails for t

Re: [Haskell-cafe] Avoiding parametric function binding

2011-12-31 Thread Yucheng Zhang
On Sat, Dec 31, 2011 at 11:09 PM, Kevin Quick wrote: >> varElem :: forall x . (Show x) => Var -> x >> varElem (V1 x) = x >> varElem (V2 x) = x >> >> main = putStrLn . elemStr . varElem $ test > The problem here is that you want the return type to depend on the 'value' of Var, which is not known u

Re: [Haskell-cafe] Avoiding parametric function binding

2011-12-31 Thread Kevin Quick
On Sat, 31 Dec 2011 08:50:05 -0700, Stephen Tetley wrote: Maybe you want a deconstructor (sometime called an eliminator)? deconsVar :: (Maybe Int -> a) -> (Maybe String -> a) -> Var -> a deconsVar f g (V1 a) = f a deconsVar f g (V2 b) = g b That works and has the advantage of allowing a si

Re: [Haskell-cafe] Avoiding parametric function binding

2011-12-31 Thread Stephen Tetley
Maybe you want a deconstructor (sometime called an eliminator)? deconsVar :: (Maybe Int -> a) -> (Maybe String -> a) -> Var -> a deconsVar f g (V1 a) = f a deconsVar f g (V2 b) = g b ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.hask

[Haskell-cafe] Avoiding parametric function binding

2011-12-31 Thread Kevin Quick
I'm having some difficulty avoiding a tight parametric binding of function parameters, which is limiting the (de)composability of my expressions. I'm curious as to whether there is an option or method I haven't tried to achieve this. Here's an example test case: data Var = V1 (Maybe Int)