Hello Ketil,

Monday, February 06, 2006, 4:06:35 PM, you wrote:

>> foo :: !Int -> !Int

KM> (Is the second ! actually meaningful?)

yes! it means that the function is strict in its result - i.e. can't return
undefined value when strict arguments are given. this sort of knowledge
should help a compiler to "propagate" strictness and figure out the
parts of program that can be compiled as strict code. really, i think
ghc is able to figure functions with strict result just like it is able to
figure strict function arguments

KM> Personally, I think is much nicer than sprinkling seq's around, and
KM> generally sufficient.  However, there could perhaps be disambiguities?

btw, it's just implemented in the GHC HEAD

KM> Last time this came up, I think examples resembling these were brought
KM> up:

KM>   foo :: [!a] -> ![a] -> a

yes, i remember this SPJ's question :)  "[!a]" means that list
elements are strict, it's the same as defining new list type with
strict elements and using it here. "![a]" means "strict list", it is
the same as defining list with "next" field strict:

data List1 a = Nil1 | List1 !a (List1 a)
data List2 a = Nil2 | List2 a !(List2 a)
data List3 a = Nil3 | List3 !a !(List3 a)

the type List3 is a simple strict list, like in any strict programming
language.

foo :: [!a] -> ![a] -> ![!a] -> a

translates to

foo :: List1 a -> List2 a -> List3 a -> a



KM>   foo' :: Map !Int String -> Int -> String

that means that keys in this map saved as strict values. for example,
the following definition

type Map a b = [(a,b)]

will be instantiated to

Map !Int String ==> [(!Int, String)]


KM> Anyway, if a reasonable semantics can be formulated, I think
KM> strictness type annotations would be a great, useful, and
KM> relatively non-intrusive (AFAICT, entirely backwards compatible)
KM> addtion to Haskell'. 

such proposal already exists and supported by implementing this in GHC
HEAD

-- 
Best regards,
 Bulat                            mailto:[EMAIL PROTECTED]



_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to