Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: [Haskell-cafe] phantom types and record syntax
(Chadda? Fouch?)
2. (no subject) (steve barak)
3. Re: (no subject) (Sumit Sahrawat, Maths & Computing, IIT (BHU))
4. Adapting code from an imperative loop (Matt Williams)
5. Re: Adapting code from an imperative loop (Bob Ippolito)
6. Re: Adapting code from an imperative loop (Matt Williams)
----------------------------------------------------------------------
Message: 1
Date: Thu, 18 Jun 2015 17:48:24 +0000
From: Chadda? Fouch? <[email protected]>
To: [email protected], beginners <[email protected]>
Subject: Re: [Haskell-beginners] [Haskell-cafe] phantom types and
record syntax
Message-ID:
<CANfjZRbh2R8T3DKKzY-nbOgjznu28ikA5V3BE6tN1LVj=mo...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Le jeu. 18 juin 2015 ? 04:45, Dimitri DeFigueiredo <[email protected]>
a ?crit :
> I am surprised that this program compiles in GHC:
>
> snip
>
> My trouble is that it seems the record syntax is *implicitly* converting
> from one type to the other. It seems I would have to remove the phantom
> type by adding a tag to avoid this:
>
This is faulty reasoning because it imply that a value changed type in your
code, based on your understanding that the record syntax is "changing" a
value...
This is not the case ! Haskell is functional, immutability is the rule. The
record syntax is just a shortcut to create a new value sharing some of its
parts with the old value. It is thus perfectly normal that the type of this
new value can be different of the type of the old value if no other
constraint prevent this (and Phantom types are by essence unconstrained by
the value, that is why they're "Phantom").
>
> But this makes me unwilling to use phantom types for security as I would
> be worried of unwittingly making the conversion.
>
>
The value of Phantom types is generally only displayed if you make them
abstract types, since the only way to constrain the phantom type is by
imposing restrictive signatures for your handling functions (and then using
those restricted functions)... This is why you usually won't export the
constructors, only smart constructors that can only produce a precise type
of value with the right phantom type. In these conditions, you can't
"unwittingly make a conversion" and your API impose a safe pattern of use,
helped by the type system to interdict unsafe combination without any
runtime cost.
>
> Could somebody sprinkle some insight into why this is "converted
> automatically" for phantom types?
> Is there another way around this?
> <http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe>
>
As I said, your perspective is wrong : there is no "conversion" here,
simply a new value with a new type. I really fail to see why you would want
your program to fail to compile, your "sanitize" is exactly the kind of
function Phantom types are for : supposing you can only create "Username
UserSupplied" with your API, and a part of your API only accept "Username
Safe", you'll need a function like sanitize to bridge those two parts.
--
Jeda?
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150618/2a9a590a/attachment-0001.html>
------------------------------
Message: 2
Date: Thu, 18 Jun 2015 17:39:46 -0700
From: steve barak <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] (no subject)
Message-ID:
<cagpkgg-jlugc5_uh0dpelodpzmkzsyy_cw-acbukahuexf+...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Unsubscribe me already!!!
Steve Barak
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150618/0ff8febc/attachment-0001.html>
------------------------------
Message: 3
Date: Fri, 19 Jun 2015 06:10:20 +0530
From: "Sumit Sahrawat, Maths & Computing, IIT (BHU)"
<[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] (no subject)
Message-ID:
<CAJbEW8M6KzGzVT=uX9rCnLuQAnCdF5=VvBJq-L1=mcfimth...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
On 19 June 2015 at 06:09, steve barak <[email protected]> wrote:
> Unsubscribe me already!!!
>
> Steve Barak
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
--
Regards
Sumit Sahrawat
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150619/7f28fbde/attachment-0001.html>
------------------------------
Message: 4
Date: Fri, 19 Jun 2015 05:51:59 +0000
From: Matt Williams <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Adapting code from an imperative loop
Message-ID:
<CAFTVGQZ-XuiveVnHLYLupjrjL0c6_TFoATB6=7olejcqwnu...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Dear All,
I have been wrestling with this for a while now.
I have a list of data items, and want to be able to access them, in a Hash
Map, via a short summary of their characteristics.
In an imperative language this might look like:
myMap = new map()
for elem in myElems:
key = makeKey(elem)
myMap[key] = myMap[key] + elem
I have been trying to do this in Haskell, but am stuck on how to hand the
Map back to itself each time.
I have a function :: elem -> [p,q] to make the key, but the Map.insert
function has the following signature:
insert :: (Hashable
<https://hackage.haskell.org/package/hashmap-1.0.0.2/docs/Data-Hashable.html#t:Hashable>
k, Ord
<https://hackage.haskell.org/packages/archive/base/4.2.0.2/doc/html/Data-Ord.html#t:Ord>
k)
=> k -> a -> HashMap
<https://hackage.haskell.org/package/hashmap-1.0.0.2/docs/Data-HashMap.html#t:HashMap>
k
a -> HashMap
<https://hackage.haskell.org/package/hashmap-1.0.0.2/docs/Data-HashMap.html#t:HashMap>
k
a
My thought was that I needed to go through the list of the elems, and at
each point add them to the Hash Map, handing the updated Map onto the next
step - but this is what I cannot write.
Any help much appreciated.
Thanks,
Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150619/619c44cd/attachment-0001.html>
------------------------------
Message: 5
Date: Fri, 19 Jun 2015 08:18:45 +0200
From: Bob Ippolito <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Adapting code from an imperative loop
Message-ID:
<CACwMPm-H6WBU_M8mYxfUO+Qbvd9UHmcvP9DFhbj0UGy1hx==l...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Friday, June 19, 2015, Matt Williams <[email protected]>
wrote:
> Dear All,
>
> I have been wrestling with this for a while now.
>
> I have a list of data items, and want to be able to access them, in a Hash
> Map, via a short summary of their characteristics.
>
> In an imperative language this might look like:
>
> myMap = new map()
> for elem in myElems:
> key = makeKey(elem)
> myMap[key] = myMap[key] + elem
>
> I have been trying to do this in Haskell, but am stuck on how to hand the
> Map back to itself each time.
>
> I have a function :: elem -> [p,q] to make the key, but the Map.insert
> function has the following signature:
>
> insert :: (Hashable
> <https://hackage.haskell.org/package/hashmap-1.0.0.2/docs/Data-Hashable.html#t:Hashable>
> k, Ord
> <https://hackage.haskell.org/packages/archive/base/4.2.0.2/doc/html/Data-Ord.html#t:Ord>
> k)
> => k -> a -> HashMap
> <https://hackage.haskell.org/package/hashmap-1.0.0.2/docs/Data-HashMap.html#t:HashMap>
> k
> a -> HashMap
> <https://hackage.haskell.org/package/hashmap-1.0.0.2/docs/Data-HashMap.html#t:HashMap>
> k
> a
>
> My thought was that I needed to go through the list of the elems, and at
> each point add them to the Hash Map, handing the updated Map onto the next
> step - but this is what I cannot write.
>
This is typically done with fromListWith or a combination of foldl' and
insertWith or alter.
-bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150619/6b295672/attachment-0001.html>
------------------------------
Message: 6
Date: Fri, 19 Jun 2015 07:05:53 +0000
From: Matt Williams <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Adapting code from an imperative loop
Message-ID:
<caftvgqzfmgt8xw7tmpuargjcwzhk+xahfhhiohzn9_erjkj...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
I tried doing it as a fold (the pattern of accumulating a value, where the
accumulated value was the resulting Map), but couldn't manage the syntax.
Have now got it partially working with fromListWith.
Thanks a lot,
Matt
On Fri, 19 Jun 2015 07:18 Bob Ippolito <[email protected]> wrote:
> On Friday, June 19, 2015, Matt Williams <[email protected]>
> wrote:
>
>> Dear All,
>>
>> I have been wrestling with this for a while now.
>>
>> I have a list of data items, and want to be able to access them, in a
>> Hash Map, via a short summary of their characteristics.
>>
>> In an imperative language this might look like:
>>
>> myMap = new map()
>> for elem in myElems:
>> key = makeKey(elem)
>> myMap[key] = myMap[key] + elem
>>
>> I have been trying to do this in Haskell, but am stuck on how to hand the
>> Map back to itself each time.
>>
>> I have a function :: elem -> [p,q] to make the key, but the Map.insert
>> function has the following signature:
>>
>> insert :: (Hashable
>> <https://hackage.haskell.org/package/hashmap-1.0.0.2/docs/Data-Hashable.html#t:Hashable>
>> k, Ord
>> <https://hackage.haskell.org/packages/archive/base/4.2.0.2/doc/html/Data-Ord.html#t:Ord>
>> k)
>> => k -> a -> HashMap
>> <https://hackage.haskell.org/package/hashmap-1.0.0.2/docs/Data-HashMap.html#t:HashMap>
>> k
>> a -> HashMap
>> <https://hackage.haskell.org/package/hashmap-1.0.0.2/docs/Data-HashMap.html#t:HashMap>
>> k
>> a
>>
>> My thought was that I needed to go through the list of the elems, and at
>> each point add them to the Hash Map, handing the updated Map onto the next
>> step - but this is what I cannot write.
>>
>
> This is typically done with fromListWith or a combination of foldl' and
> insertWith or alter.
>
> -bob
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150619/e02ff95c/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 84, Issue 30
*****************************************