Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Haskell-cafe] What is the meaning of tilde ("~") symbol

350 views
Skip to first unread message

kg

unread,
Feb 13, 2010, 8:02:08 AM2/13/10
to haskel...@haskell.org
Hi,

I'm reading the following subject :
http://www.haskell.org/pipermail/haskell-cafe/2007-July/028227.html

In the sample code, we can see :

instance ReadAsAnyOf () ex
where readAsAnyOf ~() = mzero

And, I've search the meaning of the symbol "~", but I've found nothing
about this (note that's not easy to search "~" on google ...)

Could you give me a link about this, or explain me it ?

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

Maciej Piechotka

unread,
Feb 13, 2010, 8:08:41 AM2/13/10
to haskel...@haskell.org
On Sat, 2010-02-13 at 14:03 +0100, kg wrote:
> Hi,
>
> I'm reading the following subject :
> http://www.haskell.org/pipermail/haskell-cafe/2007-July/028227.html
>
> In the sample code, we can see :
>
> instance ReadAsAnyOf () ex
> where readAsAnyOf ~() = mzero
>
>
>
> And, I've search the meaning of the symbol "~", but I've found nothing
> about this (note that's not easy to search "~" on google ...)
>
> Could you give me a link about this, or explain me it ?
>
> Thx in advance.

http://www.haskell.org/tutorial/patterns.html - Section lazy patterns

Regards

signature.asc

Andrew Coppin

unread,
Feb 14, 2010, 8:24:24 AM2/14/10
to haskel...@haskell.org
Here's an idea... maybe we should make a small page on the Wiki
explaining what all the various symbols in Haskell mean?

There are a couple which are rare enough that most tutorials don't
mention them that often. And there are of course symbols which mean
different things in different contexts. (I especially love how curly
braces are used for overriding layout *and* for named fields...)

MightyByte

unread,
Feb 14, 2010, 8:37:09 AM2/14/10
to Andrew Coppin, haskel...@haskell.org
I like that idea. When I was first learning Haskell, I remember
spending a non-trivial amount of time trying to figure out what '$'
did. I incorrectly assumed that it was provided by some library. '!'
and '~' would certainly be other good candidates for this kind of a
page. These types of things can be pretty hard to google.

Andrew Coppin

unread,
Feb 14, 2010, 8:39:26 AM2/14/10
to haskel...@haskell.org
MightyByte wrote:
> I like that idea. When I was first learning Haskell, I remember
> spending a non-trivial amount of time trying to figure out what '$'
> did. I incorrectly assumed that it was provided by some library.
>

Technically, it is...

> '!'
> and '~' would certainly be other good candidates for this kind of a
> page.

Every now and then somebody asks about "@" too.

> These types of things can be pretty hard to google.
>

Well yes, there is that too... ;-)

Of course, the next question is if we're going to do this, how to we
make it so that all the newbies stumble across this page without having
to spend 25 years tracking it down? A wiki page isn't much good if
nobody finds it...

Felipe Lessa

unread,
Feb 14, 2010, 9:41:15 AM2/14/10
to haskel...@haskell.org
On Sun, Feb 14, 2010 at 09:00:14AM -0500, MightyByte wrote:
> At any rate, they still don't help for things like '~', so
> there's definitely a use for a wiki page like this.

Of course, Hoogle and Hayoo could be modified to show the docs
when such symbols are searched as a special condition.

--
Felipe.

Henk-Jan van Tuyl

unread,
Feb 14, 2010, 11:02:53 AM2/14/10
to Andrew Coppin, haskel...@haskell.org
On Sun, 14 Feb 2010 14:24:03 +0100, Andrew Coppin
<andrew...@btinternet.com> wrote:

> Here's an idea... maybe we should make a small page on the Wiki
> explaining what all the various symbols in Haskell mean?
>
> There are a couple which are rare enough that most tutorials don't
> mention them that often. And there are of course symbols which mean
> different things in different contexts. (I especially love how curly
> braces are used for overriding layout *and* for named fields...)
>

The symbols that are not specified in a library can be found here:
http://www.haskell.org/haskellwiki/Keywords
Hoogle used to show links to this page, when a keyword was searched, but
not anymore.

--
Met vriendelijke groet,
Henk-Jan van Tuyl


--
http://Van.Tuyl.eu/
http://functor.bamikanarie.com
http://members.chello.nl/hjgtuyl/tourdemonad.html
--

Dougal Stanton

unread,
Feb 14, 2010, 11:08:05 AM2/14/10
to kg, haskel...@haskell.org
> And, I've search the meaning of the symbol "~", but I've found nothing about
> this (note that's not easy to search "~" on google ...)

Searching for "haskell tilde" produces a lot of results and they're
all relevant (on the first page at least).

D

Jake Wheat

unread,
Feb 14, 2010, 5:00:25 PM2/14/10
to haskel...@haskell.org
On 14 February 2010 16:02, Henk-Jan van Tuyl <hjg...@chello.nl> wrote:
> The symbols that are not specified in a library can be found here:
> �http://www.haskell.org/haskellwiki/Keywords
> Hoogle used to show links to this page, when a keyword was searched, but not
> anymore.

In section 5 ! on this page it says

> Finally, it is the array subscript operator:
>
> let x = arr ! 10

Shouldn't this be

let x = arr !! 10

?

Evan Laforge

unread,
Feb 14, 2010, 5:11:49 PM2/14/10
to Jake Wheat, haskel...@haskell.org
>> Finally, it is the array subscript operator:
>>
>> let x = arr ! 10
>
> Shouldn't this be
>
> let x = arr !! 10

!! is the list subscript. Look in Data.Array.IArray for (!). Or Data.Map.

There's still no consensus on typeclasses for collections, so these
are all separate functions. Has anyone taken a shot at a set of
AT-using classes for the standard collections?

wagn...@seas.upenn.edu

unread,
Feb 14, 2010, 5:18:08 PM2/14/10
to haskel...@haskell.org
Quoting Jake Wheat <jakewh...@googlemail.com>:

> On 14 February 2010 16:02, Henk-Jan van Tuyl <hjg...@chello.nl> wrote:
>> Finally, it is the array subscript operator:
>>
>> let x = arr ! 10
>
> Shouldn't this be
>
> let x = arr !! 10

(!) is for arrays, (!!) is for lists.
~d

Jake Wheat

unread,
Feb 14, 2010, 5:22:05 PM2/14/10
to haskel...@haskell.org
On 14 February 2010 22:11, Evan Laforge <qdu...@gmail.com> wrote:
>>> Finally, it is the array subscript operator:
>>>
>>> let x = arr ! 10
>>
>> Shouldn't this be
>>
>> let x = arr !! 10
>
> !! is the list subscript. �Look in Data.Array.IArray for (!). �Or Data.Map.
>
> There's still no consensus on typeclasses for collections, so these
> are all separate functions. �Has anyone taken a shot at a set of
> AT-using classes for the standard collections?
>

Oops, thanks.

That is a really useful page (http://www.haskell.org/haskellwiki/Keywords).

Evan Laforge

unread,
Feb 14, 2010, 5:41:50 PM2/14/10
to Stephen Tetley, haskel...@haskell.org
On Sun, Feb 14, 2010 at 2:22 PM, Stephen Tetley
<stephen...@gmail.com> wrote:
> On 14 February 2010 22:11, Evan Laforge <qdu...@gmail.com> wrote:
>
>> There's still no consensus on typeclasses for collections, so these
>> are all separate functions. �Has anyone taken a shot at a set of
>> AT-using classes for the standard collections?
>
>
> The standard collections have different shapes depending on what they
> represent (maps, trees, lists, sequences) so considering Functor,
> Traversable, Foldable perhaps the common operations are largely
> already covered. A unifying 'collection' class might be as problematic
> as good old Num is for numbers...

But how about indexing? It would be nice to have universal operators like

(!!) :: collection elt -> index -> elt
lookup :: index -> collection elt -> Maybe elt
member :: index -> collection elt -> Bool

That way you can have nice short names for these common operations.
Lists are very flexible but it's nothing Monoid hasn't already done
with integers and newtype wrappers, and there are plenty of others
which would be applicable (no pun intended): Map, Set, Bytestring,
Sequence.

I suppose we can get empty and concat with Monoid. What about singleton?

The names and locations are all over the map (no really, not intended)
too, symptomatic I suppose of the fact that they all evolved
separately.

Tony Morris

unread,
Feb 14, 2010, 6:13:15 PM2/14/10
to Stephen Tetley, haskel...@haskell.org
Stephen Tetley wrote:
> Hi Evan
>
> Singleton (aka wrap) would be nice - isn't it called Pointed in the
> typeclassopedia but not otherwise existent? I suppose its missing by
> historical accident rather than design.
>
> I frequently use Semigroup (append but no zero) - there is one on
> Hackage without any instances:
> http://hackage.haskell.org/package/algebra
>
I do too. I also wish there was an associative: class F f where k :: f a
-> f a -> f a without the zero component.


--
Tony Morris
http://tmorris.net/

Evan Laforge

unread,
Feb 14, 2010, 6:41:27 PM2/14/10
to Stephen Tetley, haskel...@haskell.org
> I'm no fan of (!!) on lists or other containers where it isn't O(1),
> but lookup/member are a bit more promising. However are there any
> useful derived operations or constructions that can be defined only in
> terms of a Lookup type class? For comparison, Monoid has mconcat as a
> derived op and e.g. the Writer monad can be usefully abstract by
> relying only on the Monoid interface as can Foldable.

I was thinking of (!!) as an unsafe lookup, where lookup is the safe
one. Of course historically (!!) considers lists as (Int -> elt)
while elem considers them a set, which is why you'd need some newtype
wrappers. Anyway, I'd be happy to not include the unsafe variants at
all. That would mean putting [] into Setlike with 'member' but not
Maplike with 'lookup'. You'd have to come up with a better name or
hide the Prelude alist lookup.

I don't know about derived operations, I suppose you could come up
with some sort of Evironment monad that required merely a (Maplike a)
class constraint instead of a concrete data type like Map, but for me
the prime motivation would be the short universal name. I could stick
it in my "import unqualified" toolbox and type less.

> Excepting Data.Tree, Data.Graph and HashTable, 'containers' seems
> pretty regular now - it certainly has moved on with 0.3.0.0.

Yes, and it's not a big deal to me. I use Map and Set and List and
the overhead of separate functions for each is pretty minimal. If I
used a wider variety of containers I'd probably want it more.

Neil Mitchell

unread,
Feb 16, 2010, 12:24:30 PM2/16/10
to Henk-Jan van Tuyl, haskel...@haskell.org
Hi

> The symbols that are not specified in a library can be found here:
> �http://www.haskell.org/haskellwiki/Keywords
> Hoogle used to show links to this page, when a keyword was searched, but not
> anymore.

And that's a bug:
http://code.google.com/p/ndmitchell/issues/detail?id=280 (that I only
just became aware of).

I'll fix this up shortly.

Thanks, Neil

Patrick LeBoutillier

unread,
Feb 16, 2010, 7:33:03 PM2/16/10
to haskel...@haskell.org
Hi,

> The symbols that are not specified in a library can be found here:
> �http://www.haskell.org/haskellwiki/Keywords

I noticed that \ is not in that list, should it be?

Patrick

--
=====================
Patrick LeBoutillier
Rosem�re, Qu�bec, Canada

Neil Mitchell

unread,
Feb 17, 2010, 1:56:48 AM2/17/10
to Patrick LeBoutillier, haskell-cafe
Hi Patrick,

>> The symbols that are not specified in a library can be found here:
>> �http://www.haskell.org/haskellwiki/Keywords
>
> I noticed that \ is not in that list, should it be?

Yes! Add it. If it would help a beginner understand what something
means, it should be on that list.

Thanks, Neil

Daniel Schüssler

unread,
Feb 17, 2010, 6:07:25 PM2/17/10
to haskel...@haskell.org
On Sunday 14 February 2010 17:02:36 Henk-Jan van Tuyl wrote:
> The symbols that are not specified in a library can be found here:
> http://www.haskell.org/haskellwiki/Keywords
> Hoogle used to show links to this page, when a keyword was searched, but
> not anymore.
>

This isn't Haskell 98 only, is it? :) *Adds type families, fundeps and the
arcane arrow notation*


--
Daniel

0 new messages