Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the usage of the double exclamations?

Tags:

haskell

In the Data.ByteString.Internal, the ByteString has constructor

PS !!(ForeignPtr Word8) !!Int !!Int 

What does these double exclamations mean here? I searched and just got that (!!) can be used to index a list (!!) :: [a] -> Int -> a.

like image 988
hliu Avatar asked Feb 13 '17 11:02

hliu


1 Answers

This is not part of the actual Haskell source but an (undocumented) feature of how Haddock renders unboxed data types. See https://mail.haskell.org/pipermail/haskell-cafe/2009-January/054135.html:

2009/1/21 Stephan Friedrichs <...>:

Hi,

using haddock-2.4.1 and this file:

module Test where

data Test
    = NonStrict Int
    | Strict !Int
    | UnpackedStrict {-# UNPACK #-} !Int

The generated documentation looks like this:

data Test
Constructors
 NonStrict Int
 Strict !Int
 UnpackedStrict !!Int

Note the double '!' in the last constructor. This is not intended behaviour, is it?

This is the way GHC pretty prints unboxed types, so I thought Haddock should follow the same convention. Hmm, perhaps Haddock should have a chapter about language extensions in its documentation, with a reference to the GHC documentation. That way the language used is at least documented. Not sure if it helps in this case though, since "!!" is probably not documented there.

Perhaps we should not display unbox annotations at all since they are an implementation detail, right? We could display one "!" instead, indicating that the argument is strict.

David

like image 140
melpomene Avatar answered Oct 20 '22 22:10

melpomene