[Haskell-cafe] Re: How to "Show" an Operation?
daniel.is.fischer at web.de
Fri Jun 11 04:50:34 EDT 2010
On Friday 11 June 2010 07:47:03, Martin Drautzburg wrote:
> On Friday, 11. June 2010 00:12:03 Daniel Fischer wrote:
> Thanks Daniel.
> > Upgrade. We're at 6.12 now!
> Did that. Everything is available now.
> I am still having trouble with the test function. First it seems I need
> braces, so I can mix == and <*>.
> test :: Num a
> => (a -> a) -> (a -> a) -> (a -> a) -> [String]
> test f g h = do
> [f', g', h'] <- permutations [Named "f" f, Named "g" g, Named "h" h]
> guard $ namedPure 42 == (f' <*> g' <*> h' <*> namedPure 42)
> return $ show f' ++ " . " ++ show g' ++ " . " ++ show h'
> But this leads to
> Occurs check: cannot construct the infinite type:
> a = (a -> a) -> a1 -> t
> When generalising the type(s) for `test'
Ah, yes, (<*>) is left associative (infixl 4, hence you also need the
parentheses since (==) is infix 4; same fixity and different
associativities don't mix), here it must be associated to the right,
namedPure 42 == (f' <*> (g' <*> (h' <*> namedPure 42)))
If you'd want to use it a lot, define a right associative alias with higher
infixr 5 <*<
(<*<) = (<*>)
> This error message is still the maximum penalty for me (along with
> "Corba marshall exception" in J2EE and "Missing right parenthesis" in
> Oracle SQL)
> Then generally speaking, I have the feeling that this code does not
> allow "namifying" existing code either. In this respect it does not seem
> to do better than the "apply" method pattern discussed earlier in this
You'd have to rewrite; either way.
> The problem it solves is very simple and therefore using (<*>) and
> namedPure isn't much of a drawback. But if I had tons of code to namify
> I would still have to do significant changes to it, right?
More information about the Haskell-Cafe