kell.org
| 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
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:
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 `
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
insta
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"
www.eecs.harvard.edu