Send Beginners mailing list submissions to
        beginners@haskell.org

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
        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.  Tagged types (PICCA Frederic-Emmanuel)
   2. Re:  Tagged types (Francesco Ariis)
   3. Re:  Tagged types (PICCA Frederic-Emmanuel)
   4. Re:  Tagged types (Steven Leiva)
   5. Re:  Tagged types (David McBride)
   6. Re:  Tagged types (Francesco Ariis)


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

Message: 1
Date: Tue, 2 Oct 2018 16:48:09 +0000
From: PICCA Frederic-Emmanuel
        <frederic-emmanuel.pi...@synchrotron-soleil.fr>
To: "The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell" <beginners@haskell.org>
Subject: [Haskell-beginners] Tagged types
Message-ID:
        
<a2a20ec3b8560d408356cac2fc148e53015b331...@sun-dag3.synchrotron-soleil.fr>
        
Content-Type: text/plain; charset="us-ascii"

Hello


suppose that I have a bunch  of type like this

data Unchecked
data Hdf5
data Cbf

data A t > A String

The A thing come from a database as A Unchecked

now if I read the String and it ends with  .h5, I have a A Hdf5 type
and If the string end with .cbf, I have a A Cbf.

So I would like a function which allow to return a A Hdf5 or a A Cbf depending 
on the String content.

check :: A Unchecked -> A ???
check = ???

Is it possible to do this ?

Thanks

Frederic

PS: At the end I will have more tha one tag.


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

Message: 2
Date: Tue, 2 Oct 2018 18:56:48 +0200
From: Francesco Ariis <fa...@ariis.it>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Tagged types
Message-ID: <20181002165648.tzmyistn2uwiw...@x60s.casa>
Content-Type: text/plain; charset=us-ascii

Hello Frederic,

On Tue, Oct 02, 2018 at 04:48:09PM +0000, PICCA Frederic-Emmanuel wrote:
> So I would like a function which allow to return a A Hdf5 or a A Cbf 
> depending on the String content.
> 
> check :: A Unchecked -> A ???
> check = ???
> 
> Is it possible to do this ?

I believe you can do this with GADTs [1]

[1] https://en.wikibooks.org/wiki/Haskell/GADT


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

Message: 3
Date: Tue, 2 Oct 2018 17:04:42 +0000
From: PICCA Frederic-Emmanuel
        <frederic-emmanuel.pi...@synchrotron-soleil.fr>
To: "The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell" <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Tagged types
Message-ID:
        
<a2a20ec3b8560d408356cac2fc148e53015b331...@sun-dag3.synchrotron-soleil.fr>
        
Content-Type: text/plain; charset="us-ascii"

> I believe you can do this with GADTs [1]

I can create different constructors for the different types.
but how can I create a function which return different type ?


Fred

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

Message: 4
Date: Tue, 2 Oct 2018 12:18:14 -0500
From: Steven Leiva <leiva.ste...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Tagged types
Message-ID:
        <CA+=wos6+lma5_a70yugfh_hfl78f4fxvhjchkfidss4ovmw...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Unfortunately I do not know the fancy Haskell type-level stuff, but if I
was looking at this same problem, I'd think you need a sum type:

data Unchecked = Unchecked String
data Checked = Hd5 String | Cbf String

check :: Unchecked -> Checked

There is likely a better concept than "Checked" in your domain. I do not
know what those things represent, but I would use that *ubiquitous
language* instead
- i.e., data Image ... instead of Checked.



On Tue, Oct 2, 2018 at 12:05 PM PICCA Frederic-Emmanuel <
frederic-emmanuel.pi...@synchrotron-soleil.fr> wrote:

> > I believe you can do this with GADTs [1]
>
> I can create different constructors for the different types.
> but how can I create a function which return different type ?
>
>
> Fred
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>


-- 
Steven Leiva
305.528.6038
leiva.ste...@gmail.com
http://www.linkedin.com/in/stevenleiva
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20181002/11ec17f6/attachment-0001.html>

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

Message: 5
Date: Tue, 2 Oct 2018 13:27:20 -0400
From: David McBride <toa...@gmail.com>
To: Haskell Beginners <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Tagged types
Message-ID:
        <can+tr417ajanyp1ohkeboed4uuwr60qgtuxwvb5kjkepwmd...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

You need to have some sort of either type.

check :: A Unchecked -> Either (A Hdf5) (A Cbf)

But you'll have to deal with the fact that it could be either of those
things throughout the rest of your program, somehow.

Another way would be to have

data CheckedType = Hdf5 | Cbf

check :: A Unchecked -> A CheckedType

But this has the same downside.

There may be some way with the singletons library, but I think that is out
of the scope of the newbies list.

On Tue, Oct 2, 2018 at 1:04 PM PICCA Frederic-Emmanuel <
frederic-emmanuel.pi...@synchrotron-soleil.fr> wrote:

> > I believe you can do this with GADTs [1]
>
> I can create different constructors for the different types.
> but how can I create a function which return different type ?
>
>
> Fred
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20181002/94df7526/attachment-0001.html>

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

Message: 6
Date: Wed, 3 Oct 2018 14:21:35 +0200
From: Francesco Ariis <fa...@ariis.it>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Tagged types
Message-ID: <20181003122135.wf2lryw4zjxl6...@x60s.casa>
Content-Type: text/plain; charset=us-ascii

On Tue, Oct 02, 2018 at 05:04:42PM +0000, PICCA Frederic-Emmanuel wrote:
> > I believe you can do this with GADTs [1]
> 
> I can create different constructors for the different types.
> but how can I create a function which return different type ?

Mhhh I tried to come up with an example (GADTs, ExistentialQuantification,
etc.) and failed...

This is an interesting problem and one that could interest many people;
please post your question on -cafe too (with a minimal .hs, it always
helps); I am curious on how they will approach the problem

-F



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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 124, Issue 2
*****************************************

Reply via email to