Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/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: Just how unsafe is unsafe (Roel van Dijk)
2. Re: [Haskell-cafe] Re: [Haskell-beginners] Just how unsafe is
unsafe (Colin Paul Adams)
3. Re: [Haskell-cafe] Re: [Haskell-beginners] Just how unsafe is
unsafe (Roel van Dijk)
4. Re: [Haskell-cafe] Re: [Haskell-beginners] Just how unsafe is
unsafe (Roel van Dijk)
5. Appending to a list (Francesco Bochicchio)
6. Re: Appending to a list (Cory Knapp)
7. Installing packages (Tymur Porkuian)
8. Re: Installing packages (Brandon S. Allbery KF8NH)
----------------------------------------------------------------------
Message: 1
Date: Fri, 6 Feb 2009 15:40:47 +0100
From: Roel van Dijk <[email protected]>
Subject: Re: [Haskell-beginners] Just how unsafe is unsafe
To: Antoine Latter <[email protected]>
Cc: Beginners Haskell <[email protected]>, Haskell Cafe
<[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On Fri, Feb 6, 2009 at 1:00 PM, Antoine Latter <[email protected]> wrote:
> Tangential to all of this - sometimes my unsafeXXX functions are pure,
> but partial. So I'll have:
>
> foo :: a -> b -> Maybe c
>
> and
>
> unsafeFoo :: a -> b -> c
I use the "unsafe" prefix in the same way. For me it means 'assume
that preconditions hold'. If the preconditions do not hold and you
evaluate an unsafe function anyway I would expect an error, as opposed
to an exception. I have done that in my (tiny) roman numerals package.
-- simplified
toRoman :: Int -> Either String Int
unsafeToRoman :: Int -> String
The first function is very clear about the fact that something can go
wrong. If you provide it with a value of (-3) it will (hopefully)
produce something like 'Left "no negative numbers allowed"'. The
second function hides this fact and will result in a (uncatchable)
runtime error. It is still a pure function, but preventing errors is
now the responsibility of whoever evaluates it.
------------------------------
Message: 2
Date: Fri, 06 Feb 2009 15:10:11 +0000
From: Colin Paul Adams <[email protected]>
Subject: Re: [Haskell-cafe] Re: [Haskell-beginners] Just how unsafe is
unsafe
To: Roel van Dijk <[email protected]>
Cc: Beginners Haskell <[email protected]>, Haskell Cafe
<[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-1
>>>>> "Roel" == Roel van Dijk <[email protected]> writes:
Roel> On Fri, Feb 6, 2009 at 1:00 PM, Antoine Latter <[email protected]>
wrote:
>> Tangential to all of this - sometimes my unsafeXXX functions
>> are pure, but partial. So I'll have:
>>
>> foo :: a -> b -> Maybe c
>>
>> and
>>
>> unsafeFoo :: a -> b -> c
Roel> I use the "unsafe" prefix in the same way. For me it means
Roel> 'assume that preconditions hold'. If the preconditions do
Roel> not hold and you evaluate an unsafe function anyway I would
Roel> expect an error, as opposed to an exception. I have done
Roel> that in my (tiny) roman numerals package.
Roel> -- simplified toRoman :: Int -> Either String Int
Roel> unsafeToRoman :: Int -> String
Roel> The first function is very clear about the fact that
Roel> something can go wrong. If you provide it with a value of
Roel> (-3) it will (hopefully) produce something like 'Left "no
Roel> negative numbers allowed"'. The second function hides this
Roel> fact and will result in a (uncatchable) runtime error. It is
Roel> still a pure function, but preventing errors is now the
Roel> responsibility of whoever evaluates it.
Do you document the preconditions?
It seems to me that this is more useful than naming a function
unsafeXXX.
I was using comments to document the contracts on my functions, but I
have just found about about ESC/Haskell, so I am now using the
contract notation of that (not yet released) tool.
See http://www.cl.cam.ac.uk/~nx200/
--
Colin Adams
Preston Lancashire
------------------------------
Message: 3
Date: Fri, 6 Feb 2009 19:25:18 +0100
From: Roel van Dijk <[email protected]>
Subject: Re: [Haskell-cafe] Re: [Haskell-beginners] Just how unsafe is
unsafe
To: Colin Paul Adams <[email protected]>
Cc: Beginners Haskell <[email protected]>, Haskell Cafe
<[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
> Do you document the preconditions?
Yes. The 'safe' variants of those functions have all preconditions
listed in the accompanying (haddock) comments. The 'unsafe' variants
simply state that they promote exceptions to errors.
> It seems to me that this is more useful than naming a function
> unsafeXXX.
Well, I do both :-) They are called unsafeXXX and they state why they
are unsafe.
> I was using comments to document the contracts on my functions, but I
> have just found about about ESC/Haskell, so I am now using the
> contract notation of that (not yet released) tool.
>
> See http://www.cl.cam.ac.uk/~nx200/
That is interesting. I like formal proofs and preconditions better
than informal ones.
------------------------------
Message: 4
Date: Fri, 6 Feb 2009 19:38:11 +0100
From: Roel van Dijk <[email protected]>
Subject: Re: [Haskell-cafe] Re: [Haskell-beginners] Just how unsafe is
unsafe
To: "Alberto G. Corona" <[email protected]>
Cc: Beginners Haskell <[email protected]>, Haskell Cafe
<[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On Fri, Feb 6, 2009 at 5:22 PM, Alberto G. Corona <[email protected]> wrote:
> then Data.List.head Data.Maybe.fromMaybe etc are also unsafe?.
Yes, I consider them unsafe. Whenever I see those functions I know
that I have to look elsewhere to see if their preconditions hold. I
would have preferred that listToMaybe was called head and the existing
head called unsafeHead, partialHead or something else of that nature.
> unsafe does
> not mean "with possible errors". unsafeXXX convert something in the IO monad
> into something that is not. So it can potentially contaminate your pure
> code.
> But Data.List.head applied to a empty list will interrupt the computation
> abruptly, so your code using head will either run side effect free or not
> run at all.
I guess what unsafe should mean is a matter of taste. Personally I
find correctness more important that pureness. An unsafe function will
crash your program if evaluated when its preconditions do not hold.
Whether that is because of impurity (segmentation fault?), a partial
pattern match or a direct error "bla" is not that important. It might
be important when determining why your program crashed, but the result
is still the same.
The ByteString library has a module called Data.ByteString.Unsafe with
plenty of unsafeXXX functions. The comment for unsafeHead for example
states: "A variety of head for non-empty ByteStrings. unsafeHead omits
the check for the empty case, so there is an obligation on the
programmer to provide a proof that the ByteString is non-empty." That
perfectly reflects my own philosophy on this issue.
------------------------------
Message: 5
Date: Sat, 7 Feb 2009 21:29:39 +0100
From: Francesco Bochicchio <[email protected]>
Subject: [Haskell-beginners] Appending to a list
To: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hi all,
in my haskell exercises I often build list by appending values at the end.
But I read somewhere that in haskell this is inefficient since there is no
'pointer to the tail of the list'. I've also seen some example of recursive
functions which build the list tail-first and then in the base case of the
recursion returns the reverse of the accumulated results, counting on the
fact
that in haskell 'reverse list' just means 'consume the list from the tail'.
Just out of curiosity (I have no need to speed up my little programs with
which I try to teach myself
some haskell): is this a consolidated pattern? And are append really
expensive?
Ciao
-------
FB
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20090207/e53cdee4/attachment-0001.htm
------------------------------
Message: 6
Date: Sat, 07 Feb 2009 15:04:06 -0600
From: Cory Knapp <[email protected]>
Subject: Re: [Haskell-beginners] Appending to a list
To: Francesco Bochicchio <[email protected]>
Cc: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
In general, you want to be building a list "from the front". Consider
the list constructor-- x:xs is a list, when x is an element, and xs is a
list; on the other hand, xs:x will give you a type error. I think the
lisp syntax is a bit more elucidating; in lisp, you use "cons" to create
a pair e.g. (cons 1 2), and to create a list, you make a pair whose last
element is empty, and cons elements to the front. E.g. (cons 2 '())
gives you the list '(2), which is lisp for [2], and (cons 1 (cons 2
(cons 3 (cons 4 '() ) ) ) ) gives you '(1 2 3 4)-- lisp for [1,2,3,4]).
In order to add the end of the list, you need to unravel the whole list,
(replacing the '() at the end with "(cons 5 '())" ). On the other hand,
adding to the front requires you to just cons another value to it.
Haskell works the same way, but it uses an infix operator [1,2,3,4] =
1:2:3:4:[] = 1 : (2 : (3 : (4 : [] ) ) ). So appending to the list is
expensive, while adding to the front just requires x : list.
Obviously, if you're actually concatenating two lists, you need to
filter through one of them anyway, but if you're just putting an element
on, it's better to put it on the front.
Normally, this is practically accomplished by making recursive
procedures which work towards the end of the list. For example, map will
apply a function to the first element and then map to the rest:
map f (x:xs) = (f x) : (map f xs)
map _ [] = []
So, you use your list as a stack-- pulling everything off, and then
placing it all back on with the function applied.
Does that help, or did I miss the point?
Cheers,
Cory Knapp
Francesco Bochicchio wrote:
> Hi all,
>
> in my haskell exercises I often build list by appending values at the end.
> But I read somewhere that in haskell this is inefficient since there
> is no
> 'pointer to the tail of the list'. I've also seen some example of
> recursive
> functions which build the list tail-first and then in the base case of the
> recursion returns the reverse of the accumulated results, counting on
> the fact
> that in haskell 'reverse list' just means 'consume the list from the
> tail'.
>
> Just out of curiosity (I have no need to speed up my little programs
> with which I try to teach myself
> some haskell): is this a consolidated pattern? And are append really
> expensive?
>
> Ciao
> -------
> FB
> ------------------------------------------------------------------------
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 7
Date: Sun, 8 Feb 2009 03:50:17 +0200
From: Tymur Porkuian <[email protected]>
Subject: [Haskell-beginners] Installing packages
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
I'm trying to install wxcore-0.11.0 using Cabal. I've downloaded it
from http://hackage.haskell.org/cgi-bin/hackage-scripts/package/wxcore-0.11.0,
unpacked and tried to follow instructions from
http://haskell.org/haskellwiki/Cabal/How_to_install_a_Cabal_package,
but this is what I'm getting:
D:\libraries\wxcore-0.11.0>runhaskell Setup configure
Setup: sh: runGenProcess: does not exist (No such file or directory)
What does this mean?
------------------------------
Message: 8
Date: Sat, 7 Feb 2009 22:42:15 -0500
From: "Brandon S. Allbery KF8NH" <[email protected]>
Subject: Re: [Haskell-beginners] Installing packages
To: [email protected]
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
On 2009 Feb 7, at 20:50, Tymur Porkuian wrote:
> I'm trying to install wxcore-0.11.0 using Cabal. I've downloaded it
> from http://hackage.haskell.org/cgi-bin/hackage-scripts/package/wxcore-0.11.0
> ,
> unpacked and tried to follow instructions from
> http://haskell.org/haskellwiki/Cabal/How_to_install_a_Cabal_package,
> but this is what I'm getting:
>
> D:\libraries\wxcore-0.11.0>runhaskell Setup configure
> Setup: sh: runGenProcess: does not exist (No such file or directory)
>
> What does this mean?
On Windows it usually means that the package has a "configure" shell
script and therefore requires that Cygwin or MSYS be installed.
--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [email protected]
system administrator [openafs,heimdal,too many hats] [email protected]
electrical and computer engineering, carnegie mellon university KF8NH
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url :
http://www.haskell.org/pipermail/beginners/attachments/20090207/2d6072e9/PGP.bin
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 8, Issue 5
***************************************