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: better exception handling (Henk-Jan van Tuyl)
2. Empty type (KwangYul Seo)
3. Re: Empty type (Ben Gamari)
4. Re: Empty type (Kim-Ee Yeoh)
5. Re: Empty type (AntC)
6. reifying based-on type of a newtype or data (AntC)
7. Re: reifying based-on type of a newtype or data (AntC)
8. Re: Empty type (Brent Yorgey)
----------------------------------------------------------------------
Message: 1
Date: Fri, 25 Oct 2013 00:09:14 +0200
From: "Henk-Jan van Tuyl" <[email protected]>
To: "The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell" <[email protected]>,
"Miro Karpis" <[email protected]>, "The Haskell-Beginners
Mailing List - Discussion of primarily beginner-level topics related
to Haskell" <[email protected]>
Subject: Re: [Haskell-beginners] better exception handling
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-15; format=flowed;
delsp=yes
On Wed, 23 Oct 2013 23:11:32 +0200, Miro Karpis
<[email protected]> wrote:
> Please, can you help me with following?... I have a working code but am
> not
> very happy with the error handling in "updateStocks" function. It does
> what
> it should, but I would like to implement some kind of guards. Problem is
> that it always ends it some error + am not sure if I can use guards in
> inside defined variable. Pls. what would you suggest?
>
>
>
> httpExceptionHandler :: HttpException -> IO L.ByteString
> httpExceptionHandler e = (putStrLn "Error: simpleHttp returned
> exception")
> >> (return L.empty)
>
> getStocks :: String -> IO L.ByteString
> getStocks url = (simpleHttp url) `X.catch` httpExceptionHandler
>
> updateStocks :: IO String
> updateStocks = do
> yqlResult <- getStocks testQuery
> case yqlResult of x | x == L.empty -> return "return exception"
> | otherwise -> return "here I will call
> another function"
I think you need to give more details to say anything about this. What is
the indication that there is nothing more to download?
I have some suggestions for code improvement:
- you use more parentheses than necessary, download hlint from hackage, it
can suggest improvements
- the code:
> case yqlResult of x | x == L.empty -> return "return exception"
> | otherwise -> return "here I will call another
> function"
can be simplified to:
> if yqlResult == L.empty then return "return exception"
> else return "here I will call another function"
or even:
> return if yqlResult == L.empty then "return exception"
> else "here I will call another function"
Regards,
Henk-Jan van Tuyl
--
Folding@home
What if you could share your unused computer power to help find a cure? In
just 5 minutes you can join the world's biggest networked computer and get
us closer sooner. Watch the video.
http://folding.stanford.edu/
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
Haskell programming
--
------------------------------
Message: 2
Date: Fri, 25 Oct 2013 12:44:06 +0900
From: KwangYul Seo <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Empty type
Message-ID:
<CACLRxYXMi-DOfDSLBa5hRHLwdSqZt=JpK4MSvvT=ZBYPT=x...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hello,
It seems there are three different ways to declare an empty type in Haskell.
http://www.haskell.org/haskellwiki/Empty_type
1) data E0 = E0
2) newtype Void = Void Void
3) data Void
I'd like to know how the second trick works. Is it possible to create a new
type from itself? How should I interpret this?
Thanks,
Kwang Yul Seo
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131025/a093097a/attachment-0001.html>
------------------------------
Message: 3
Date: Fri, 25 Oct 2013 01:06:22 -0400
From: Ben Gamari <[email protected]>
To: KwangYul Seo <[email protected]>, [email protected]
Subject: Re: [Haskell-beginners] Empty type
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
KwangYul Seo <[email protected]> writes:
> Hello,
>
> It seems there are three different ways to declare an empty type in Haskell.
>
> http://www.haskell.org/haskellwiki/Empty_type
>
> 1) data E0 = E0
>
Perhaps this is a bit nit-picky, but is this truly empty? I would
actually argue that the type is inhabited by precisely one element,
`E0` (note that we aren't counting _|_).
> 2) newtype Void = Void Void
>
> 3) data Void
>
> I'd like to know how the second trick works. Is it possible to create a new
> type from itself? How should I interpret this?
>
I'll try to answer as far as I understand it but someone please correct
any mistruths below.
Consider your type,
newtype Void = Void Void
There are only two ways we could construct a value of type `Void`,
a = Void _|_
and,
b = Void b
However, `b` is a non-terminating recursion, making it equivalent to
`a`. By this reasoning, since both of these constructions evaluate to
_|_, `Void` must be empty.
Cheers,
- Ben
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 489 bytes
Desc: not available
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131025/97e3c220/attachment-0001.sig>
------------------------------
Message: 4
Date: Fri, 25 Oct 2013 15:04:51 +0700
From: Kim-Ee Yeoh <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Empty type
Message-ID:
<CAPY+ZdS_sUfKoK=sjMfwmP+t0L_A=_JNkskX4xLgvN=dukp...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
On Fri, Oct 25, 2013 at 10:44 AM, KwangYul Seo <[email protected]> wrote:
> 2) newtype Void = Void Void
It's a Catch-22:
you: So tell me how to create smth of type Void
newtype: Sure, I can do that! After all, I'm the declaration of the type,
aren't I? But first, you gotta do something for me.
you: Ok, what's that?
newtype: gimme smth of type Void --- MWAHAHAHAHA
you: (trolled hard)
-- Kim-Ee
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131025/0a661c87/attachment-0001.html>
------------------------------
Message: 5
Date: Fri, 25 Oct 2013 09:05:05 +0000 (UTC)
From: AntC <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Empty type
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
> KwangYul Seo <skyul <at> company100.com> writes:
>
> It seems there are three different ways to declare an empty type in Haskell.
>
> http://www.haskell.org/haskellwiki/Empty_type
>
Hi KwangYul, it seems someone was playing games writing that page. I suggest
you look at:
http://www.haskell.org/ghc/docs/7.6.3/html/users_guide/data-type-
extensions.html#nullary-types
So the answer is that there is one way to declare an empty type; and it's
method 3) from your OP.
I agree with Ben that method 1) is not truly empty.
And I like both Ben's and Kim-Ee's explanations why 2) is kinda empty and
kinda not. (Trying to use Void will almost certainly make your program loop.
Using method 1) or 3) won't.)
AntC
------------------------------
Message: 6
Date: Fri, 25 Oct 2013 09:28:02 +0000 (UTC)
From: AntC <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] reifying based-on type of a newtype or
data
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
So I have (or rather the user of my package has):
> {-# LANGUAGE DeriveDataTypeable #-}
>
> newtype Foo = Foo Int deriving (Read, Show, Typeable, Data, ...)
> someFoo = Foo Int
>
Note:
* the `newtype` could be `data` -- if that would help.
* this is _not_ a parameterised type, but a 'baked in' `Int`.
* the data constr is named same as the type -- if that would help.
I can ask for `typeOf someFoo` and get `Foo` OK.
I can ask for `typeOf Foo` and get `Int -> Foo` OK.
If I ask for `typeOf (typeOf someFoo)` I get `TypeRep`.
`typeOf (show $ typeOf someFoo`) gets me `[Char]` (aka `String`)
So far very logical, but not very helpful.
What I want is to get the based-on type baked inside `someFoo`
-- that is: `Int`
(It would also be handy to get the name of the data constr, just in case
it's different to the type.)
Do I need to get into `deriving (..., Generic)` ?
That looks like serious machinery!
Thanks
AntC
------------------------------
Message: 7
Date: Fri, 25 Oct 2013 09:30:17 +0000 (UTC)
From: AntC <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] reifying based-on type of a newtype
or data
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
> someFoo = Foo Int
Oops! That should be:
> someFoo = Foo 5
------------------------------
Message: 8
Date: Fri, 25 Oct 2013 07:54:18 -0400
From: Brent Yorgey <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Empty type
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Fri, Oct 25, 2013 at 12:44:06PM +0900, KwangYul Seo wrote:
> Hello,
>
> It seems there are three different ways to declare an empty type in Haskell.
>
> http://www.haskell.org/haskellwiki/Empty_type
>
> 1) data E0 = E0
This one is not empty, as others have pointed out. It is inhabited by _|_ and
E0.
> 2) newtype Void = Void Void
This one is in fact empty (that is, only inhabited by _|_), but it
depends on the fact that newtype constructors do not add any laziness.
The same thing done with 'data',
data NotVoid = NotVoid NotVoid
is not empty, because it is inhabited by
_|_, NotVoid _|_, NotVoid (NotVoid _|_), ...
With the data declaration, these are all different. With the newtype,
they are all equal to _|_. This is a bit of a technical point,
however; if I were you I wouldn't worry about it at this point. It
sounds like the most important thing for you to understand is below:
> I'd like to know how the second trick works. Is it possible to create a new
> type from itself? How should I interpret this?
Yes, it is possible to create a new type from itself! This is called
a "recursive data type", and they are the bread and butter of Haskell
programming. For some other less silly/trivial examples, consider
data IntList = Nil | Cons Int IntList
data BTree a = Empty | Node a (BTree a) (BTree a)
both of which are recursive types.
-Brent
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 64, Issue 37
*****************************************