Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

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" <hjgt...@chello.nl>
To: "The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell" <Beginners@haskell.org>,
        "Miro Karpis" <miroslav.kar...@gmail.com>, "The Haskell-Beginners
        Mailing List - Discussion of primarily beginner-level topics related
        to Haskell" <beginners@haskell.org>
Subject: Re: [Haskell-beginners] better exception handling
Message-ID: <op.w5hbtodfpz0...@zen5.arnhem.chello.nl>
Content-Type: text/plain; charset=iso-8859-15; format=flowed;
        delsp=yes

On Wed, 23 Oct 2013 23:11:32 +0200, Miro Karpis  
<miroslav.kar...@gmail.com> 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 <sk...@company100.com>
To: beginners@haskell.org
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 <bgamari.f...@gmail.com>
To: KwangYul Seo <sk...@company100.com>, beginners@haskell.org
Subject: Re: [Haskell-beginners] Empty type
Message-ID: <87zjpydjn5....@gmail.com>
Content-Type: text/plain; charset="us-ascii"

KwangYul Seo <sk...@company100.com> 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 <k...@atamo.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
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 <sk...@company100.com> 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 <anthony_clay...@clear.net.nz>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Empty type
Message-ID: <loom.20131025t105520-...@post.gmane.org>
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 <anthony_clay...@clear.net.nz>
To: beginners@haskell.org
Subject: [Haskell-beginners] reifying based-on type of a newtype or
        data
Message-ID: <loom.20131025t110935-...@post.gmane.org>
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 <anthony_clay...@clear.net.nz>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] reifying based-on type of a newtype
        or data
Message-ID: <loom.20131025t112930-...@post.gmane.org>
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 <byor...@seas.upenn.edu>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Empty type
Message-ID: <20131025115418.ga23...@seas.upenn.edu>
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
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 64, Issue 37
*****************************************

Reply via email to