RE: [Haskell-cafe] function types as instances of Num

2006-11-01 Thread Simon Peyton-Jones
| Subject: [Haskell-cafe] function types as instances of Num | | | Let's say we've got a little stack language, where you compute | things by transformations of stacks, using compositions of functions | from stacks to stacks (represented here as nested tuples). (See also | Chris Okasaki's

[Haskell-cafe] function types as instances of Num

2006-10-26 Thread Greg Buchholz
Let's say we've got a little stack language, where you compute things by transformations of stacks, using compositions of functions from stacks to stacks (represented here as nested tuples). (See also Chris Okasaki's Techniques for Embedding Postfix Languages in Haskell

Re: [Haskell-cafe] function types as instances of Num

2006-10-26 Thread Dan Weston
How about: {-# OPTIONS -fglasgow-exts #-} import Control.Arrow type Alpha alpha = alpha - (Integer,alpha) test = square . (lit 4) lit :: Integer - Alpha alpha lit val stack= (val, stack) instance Eq (Alpha alpha) where x == y = uncurry (==) . (fst . x fst . y) $ undefined instance

Re: [Haskell-cafe] function types as instances of Num

2006-10-26 Thread Greg Buchholz
Dan Weston wrote: How about: Hmm. I'm probably being dense today, but when I add the following definitions to your program... main = print $ (square . 4) () square (a,b) = (a*a,b) ...I still get the same error... No instance for (Num (() - (t, t1))) arising from the literal

Re: [Haskell-cafe] function types as instances of Num

2006-10-26 Thread Dan Weston
You need to monomorphize the result before printing: main = print $ ((square . 4) :: Alpha ()) Presumably you will apply (square . 4) at some point to a concrete state at some point, and you wouldn't need to provide the type explicitly. Greg Buchholz wrote: Dan Weston wrote: How about: