Re: [Haskell-cafe] Safe 'chr' function?

2013-01-03 Thread Sai Hemanth K
>Alternatively, is there a way to know ahead of time whether or not an Int
will cause 'chr' to throw an exception?

since Char is in instance of 'Bounded' as well as 'Enum'

wouldn't fromEnum (maxBound :: Char) give the max value of Int for which a
valid char exists?


On Thu, Jan 3, 2013 at 1:20 PM, Myles C. Maxfield
wrote:

> Hello,
> I'm working on a general text-processing library [1] and one of my
> quickcheck tests is designed to make sure that my library doesn't throw
> exceptions (it returns an Either type on failure). However, there are some
> inputs that cause me to pass bogus values to the 'chr' function (such
> as 1208914), which causes it to throw an exception. Is there a version of
> that function that is safe? (I'm hoping for something like Int -> Maybe
> Char). Alternatively, is there a way to know ahead of time whether or not
> an Int will cause 'chr' to throw an exception?
>
> Thanks,
> Myles C. Maxfield
>
> [1] http://hackage.haskell.org/package/punycode
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>


-- 
I drink I am thunk.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Safe 'chr' function?

2013-01-03 Thread Michael Snoyman
You could wrap chr with a call to spoon[1]. It's not the most elegant
solution, but it works.

[1]
http://hackage.haskell.org/packages/archive/spoon/0.3/doc/html/Control-Spoon.html#v:spoon


On Thu, Jan 3, 2013 at 9:50 AM, Myles C. Maxfield
wrote:

> Hello,
> I'm working on a general text-processing library [1] and one of my
> quickcheck tests is designed to make sure that my library doesn't throw
> exceptions (it returns an Either type on failure). However, there are some
> inputs that cause me to pass bogus values to the 'chr' function (such
> as 1208914), which causes it to throw an exception. Is there a version of
> that function that is safe? (I'm hoping for something like Int -> Maybe
> Char). Alternatively, is there a way to know ahead of time whether or not
> an Int will cause 'chr' to throw an exception?
>
> Thanks,
> Myles C. Maxfield
>
> [1] http://hackage.haskell.org/package/punycode
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Safe 'chr' function?

2013-01-03 Thread Myles C. Maxfield
Thanks you two for your answers. Consider this issue closed now :-)

--Myles

On Thu, Jan 3, 2013 at 12:05 AM, Michael Snoyman wrote:

> You could wrap chr with a call to spoon[1]. It's not the most elegant
> solution, but it works.
>
> [1]
> http://hackage.haskell.org/packages/archive/spoon/0.3/doc/html/Control-Spoon.html#v:spoon
>
>
> On Thu, Jan 3, 2013 at 9:50 AM, Myles C. Maxfield <
> myles.maxfi...@gmail.com> wrote:
>
>> Hello,
>> I'm working on a general text-processing library [1] and one of my
>> quickcheck tests is designed to make sure that my library doesn't throw
>> exceptions (it returns an Either type on failure). However, there are some
>> inputs that cause me to pass bogus values to the 'chr' function (such
>> as 1208914), which causes it to throw an exception. Is there a version of
>> that function that is safe? (I'm hoping for something like Int -> Maybe
>> Char). Alternatively, is there a way to know ahead of time whether or not
>> an Int will cause 'chr' to throw an exception?
>>
>> Thanks,
>> Myles C. Maxfield
>>
>> [1] http://hackage.haskell.org/package/punycode
>>
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Lens, with ability to create a data-field when it's missing

2013-01-03 Thread Takayuki Muranushi
Dear All, I really am enjoying the lens (it is tough to learn, though :)

Recently, I've been trying to implement a dynamic object --- a
collection of methods that you can update at run-time --- using lens
[1][2][3]. After several attempts, I think I have located the center
of my problem:

Lens with the ability "to create a data-field when it's missing." My
question: is it possible?

There are many excellent examples of partial lenses in the lens
library, such as '_head' from Data.List.Lens 'dynamic' from
Data.Dynamic.Lens . To me, they seem to share the following set of
common behavior (allow me to use inaccurate terms...)

- set l a s : if the field is present, insert 'a'; otherwise, do nothing.
- over l f s : if the field is present, map 'f' over it. otherwise, do nothing.
- preview l s : if the field is present, return 'Just a'. otherwise,
return 'Nothing' .

Instead, I want the following set of behaviors:

- set l a s : if the field is present, insert 'a'; otherwise, *create
the field* and insert 'a'.
- over l f s : if the field is present, map 'f' over it. otherwise, do nothing.
- preview l s : if the field is present, return 'Just a'. otherwise,
return 'Nothing' .

For example, the current behavior of _head is
>>> [] & _head .~ 1
[]
I want to implement a variant _head' , such that
>>> [] & _head' .~ 1
[1]


Let us call this behavior 'Member' for the moment.

I have a implementation of 'Member' [4][5] but they are
unsatisfactory. [4] involves runtime errors and breaking of lens laws.
[5] shows that we can "create a field" only if we treat Dynamic
explicitly out of lens context.

I don't know how 'Member' will fit in the lens hierarchy
http://i.imgur.com/FgfVW.png or even if it fits at all.
Member is weaker than Getter and probably is a Fold since you have
only partial getting (^?) for Member. Member is weaker than Prism
since you cannot construct a whole Object from just one Member. On the
other hand, setter side of Member requires (s -> b -> t) interface of
a Lens, because the setter need to update the whole Object when the
field under concern is missing.

That said, let me put this question in another way;

" We can construct a (Simple Lens s a) from (getter :: s -> a) and
(setter :: s -> a -> s), and we can construct a (Getter s a) from
(getter :: s -> a).
  Then why we cannot construct a (Simple Setter s a) from (setter :: s
-> a -> s) ? "

Does Member deserve a new node in The Lens Hierarchy tree? Or can we
implement it by combinations of existing prisms, folds etc? Or does it
fall outside of the lens framework?

I appreciate any comments.
Takayuki

[1] https://github.com/nushio3/practice/tree/master/duck
[2] http://d.hatena.ne.jp/nushio/20121226#p2 (Japanese)
[3] 
http://hackage.haskell.org/packages/archive/dynamic-object/0.1.0.1/doc/html/Data-Object-Dynamic-Types.html
[4] https://github.com/nushio3/practice/blob/master/lens/newfield.hs
[5] https://github.com/nushio3/practice/blob/master/lens/object-4.hs


--
Takayuki MURANUSHI
The Hakubi Center for Advanced Research, Kyoto University
http://www.hakubi.kyoto-u.ac.jp/02_mem/h22/muranushi.html

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


Re: [Haskell-cafe] Object Oriented programming for Functional Programmers

2013-01-03 Thread Alberto G. Corona
Anyway, Type checking is essentially an application of set theory : (I did
no search in te literature for this, It is just my perception). When I say
  (+) :: Num a => a -> a -> a . I mean that (+) takes two elements of the
set of Num typeclass and return another. This is in principle a weak
restriction, because many functions do it as well, for example (*).

A propery check or a contract would be much more restrictive and thus would
detect much more program errors. But it seems that no other language but
haskell took this set theoretical analysis so exhaustively, and without it,
a property check is like detecting microscopic cracks in nuclear waste
vessel without first making sure that the cover has been sealed.


2013/1/2 MigMit 

>
> On Jan 3, 2013, at 2:09 AM, Gershom Bazerman  wrote:
>
> > On 1/2/13 4:29 PM, MigMit wrote:
> >>
> >>> BTW. Why you think that Eiffel type system is unsafe?
> >> Well, if I remember correctly, if you call some method of a certain
> object, and this call compiles, you can't be certain that this object
> actually has this method. Could be that this object belongs to some
> subclass which removes this method.
> >>
> >
> > Eiffel doesn't handle the relationship of co- and contra-variance of
> arguments with subtyping in a principled way. This is apparently known as
> the "catcall" problem. See, e.g., this article:
> http://www.eiffelroom.org/node/517
>
> Yes, variance is another big source of unsafety, that's for sure. And
> another reason I think there is no real "theory" behind Eiffel, just a
> bunch of features (or "concepts") boiled together.
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



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


Re: [Haskell-cafe] Mancunian Haskellers out there?

2013-01-03 Thread James Jeffries
Hi there

There isn't currently a haskell user groupu in Manchester, however there is
a functional programming group where a lot of the member s are haskellers.

http://www.lambdalounge.org.uk/
https://groups.google.com/forum/?fromgroups#!forum/lambda-lounge-manchester

It is at Madlab in the Northern Quarter and there is usually a trip to the
pub afterwards.

Thanks
James

On 30/12/12 14:38, Alfredo Di Napoli wrote:

Morning Cafe,

I've been living in Manchester for 1 month now and I'm
wondering if some on you are from the Greater Manchester area,
so that we could chat about out beloved language in front of a
glass of ale / tea :P

Happy new year to everyone!
A.


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


Re: [Haskell-cafe] Proving programs

2013-01-03 Thread satvik chauhan
Which book does that chapter belongs to?

-Satvik

On Thu, Jan 3, 2013 at 11:44 AM, Andrés Sicard-Ramírez <
andres.sicard.rami...@gmail.com> wrote:

> On Wed, Jan 2, 2013 at 12:22 PM, Simon Thompson 
> wrote:
> > Christopher, there's an introduction to proof for functional programs at
> >
> >   http://www.cs.kent.ac.uk/people/staff/sjt/Pubs/ProofChapter.pdf
> >
>
> Simon, is it possible to get the list of the bibliographic references
> used in the chapter?
>
> Best regards,
>
> --
> Andrés
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Proving programs

2013-01-03 Thread Andrés Sicard-Ramírez
On Thu, Jan 3, 2013 at 8:07 AM, satvik chauhan  wrote:
> Which book does that chapter belongs to?

http://www-fp.dcs.st-and.ac.uk/pfpbook/

-- 
Andrés

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


Re: [Haskell-cafe] [Haskell] Importing Repa library

2013-01-03 Thread Henning Thielemann


On Thu, 3 Jan 2013, Емануела Моллова wrote:


Hello! :)


I think you should better post your question to haskell-cafe@haskell.org.


Then I put this script 

import qualified Data.Array.Repa as R
:m +Data.Array.Repa
Z

into the file "file.hs",


This is GHCi syntax, but it is not a valid Haskell module as indicated by 
the .hs filename extension.



opened WinGHCi and loaded the file, and then evaluated it, but what I get is: 

Could not find module `Data.Array.Repa'
Perhaps you meant
Data.Array.Base (from array-0.4.0.0)
Data.Array.IO (from array-0.4.0.0)
Data.Array.ST (from array-0.4.0.0)
Use -v to see a list of the files searched for.
Failed, modules loaded: none.


I wonder why it loads file.hs at all. I would expect that it gives a 
syntax error.




Also ghc-pkg list repa says:

WARNING: cache is out of date: C:/Program Files/Haskell 
Platform/2012.4.0.0\lib\package.conf.d\package.cache
use 'ghc-pkg recache' to fix. C:/Program Files/Haskell 
Platform/2012.4.0.0\lib\package.conf.d:
C:\Users\Faery\AppData\Roaming\ghc\i386mingw32-7.4.2\package.conf.d:



Since 'repa' is not listed, it was not installed successfully. This would 
be consistent with the "Could not find module" message of GHCi. You may 
post the output of the 'cabal install repa' run.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Mancunian Haskellers out there?

2013-01-03 Thread Alfredo Di Napoli
Great news James, thanks!
I've checked on the map and is near Piccadilly Gardens, in the heart of
Manchester!
I'll join the google group and attend the next meeting for sure :)

Cheers,
A.

On 3 January 2013 12:59, James Jeffries  wrote:

> Hi there
>
> There isn't currently a haskell user groupu in Manchester, however there
> is a functional programming group where a lot of the member s are
> haskellers.
>
> http://www.lambdalounge.org.uk/
> https://groups.google.com/forum/?fromgroups#!forum/lambda-lounge-manchester
>
> It is at Madlab in the Northern Quarter and there is usually a trip to the
> pub afterwards.
>
> Thanks
> James
>
> On 30/12/12 14:38, Alfredo Di Napoli wrote:
>
> Morning Cafe,
>
> I've been living in Manchester for 1 month now and I'm
> wondering if some on you are from the Greater Manchester area,
> so that we could chat about out beloved language in front of a
> glass of ale / tea :P
>
> Happy new year to everyone!
> A.
>
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org   >
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Object Oriented programming for Functional Programmers

2013-01-03 Thread Timon Gehr

On 01/03/2013 10:56 AM, Alberto G. Corona wrote:

Anyway, Type checking is essentially an application of set theory : (I
did no search in te literature for this, It is just my perception).


Not exactly. Type theory is not an application of set theory, it is an 
alternative to set theory.



When
I say   (+) :: Num a => a -> a -> a . I mean that (+) takes two elements
of the set of Num typeclass and return another.


If I get this right, you consider Num to be a set, and then its 
inhabitants would need to be be types, thus this describes a type-level 
mapping.

This is a more accurate description, (but there might be a better one):

(+) : (a : Type)->(i : (Num a : Prop))->(x : a)->(y : a)->(z : a)

(+) is a mapping from types 'a' to mappings from proofs 'i' of the 
proposition that 'a' is an instance of the 'Num' type class to a curried 
function that takes two arguments of type 'a' and produces a result of 
type 'a'.



This is in principle a
weak restriction, because many functions do it as well, for example (*).

A propery check or a contract would be much more restrictive and thus
would detect much more program errors. But it seems that no other
language but haskell took this set theoretical analysis so exhaustively,


There are quite a few that take it further than Haskell.

http://wiki.portal.chalmers.se/agda/pmwiki.php



and without it, a property check is like detecting microscopic cracks in
nuclear waste vessel without first making sure that the cover has been
sealed.




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


Re: [Haskell-cafe] Object Oriented programming for Functional Programmers

2013-01-03 Thread Timon Gehr

On 01/02/2013 11:19 PM, MigMit wrote:


On Jan 3, 2013, at 2:09 AM, Gershom Bazerman  wrote:


On 1/2/13 4:29 PM, MigMit wrote:



BTW. Why you think that Eiffel type system is unsafe?

Well, if I remember correctly, if you call some method of a certain object, and 
this call compiles, you can't be certain that this object actually has this 
method. Could be that this object belongs to some subclass which removes this 
method.



Eiffel doesn't handle the relationship of co- and contra-variance of arguments with 
subtyping in a principled way. This is apparently known as the "catcall" 
problem. See, e.g., this article: http://www.eiffelroom.org/node/517


Yes, variance is another big source of unsafety, that's for sure. And another reason I think there 
is no real "theory" behind Eiffel, just a bunch of features (or "concepts") 
boiled together.



There seem to be efforts to fix this:
http://tecomp.sourceforge.net/index.php?file=doc/papers/proof/

The resulting language appears to be type safe:
http://tecomp.sourceforge.net/index.php?file=doc/papers/lang/modern_eiffel.txt#chapter_20




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


[Haskell-cafe] Fwd: Foreign.Erlang help

2013-01-03 Thread Junior White
Hi Alexandar,
  Thanks for your help! I give up Foreign.Erlang and try usual tcp server
in Haskell instead.

-- Forwarded message --
From: Junior White 
Date: Fri, Jan 4, 2013 at 3:18 PM
Subject: Re: [Haskell-cafe] Foreign.Erlang help
To: Alexander Alexeev 


Hi Alexandar,
  Thanks for your help! I'll give up Foreign.Erlang and try usual tcp
server in Haskell instead.



On Tue, Dec 25, 2012 at 4:08 PM, Alexander Alexeev  wrote:

>  First of all, you can write usual TCP server in Haskell and use it from
> Erlang. It would be handy to use some widely used protocol, like Memcached
> or Redis.
>
> If in some reason you want to use Foreign.Erlang, make sure that you are
> using the same cookie and the same node name type (short or full) in Erlang
> node and Haskell application.
>
>
> On 12/24/2012 08:46 PM, Junior White wrote:
>
> Hi all,
>   I have a game server programming in erlang, but now i want to write some
> game logic in haskell, how to write a haskell node for erlang?
>
>ps:I have read the introduce of Foreign.Erlang,I use haskell send a
> message to a erlang echo server, but the server not receive anything.
>
>
> ___
> Haskell-Cafe mailing 
> listHaskell-Cafe@haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
>
> --
> Best regards,
> Alexander Alexeevhttp://eax.me/
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe