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
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
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
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
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
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)