phantom type

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

phantom type

PICCA Frederic-Emmanuel
Hello,

Here my problem.
I extract some information from a database and put them into a type with 50 parameters

Type MyData = MyData Int String ...

But I need to be able to differenciate two different case. depending on the String content.
something like if the String start with "ref-" it is a Caracterization and if not it is a Collect

So I end up with this solution

data Unchecked
data Caracterization
data Collect

data MyData t = MyData Int String ...

now I defined a function

getMyDataFromDatabase :: ... -> Mydata Unchecked

and isCollect in order to verify that I have a Collect and not something Else

isACollect :: MyData Unchecked -> Either Text (MyData Collect).

which use coerc in order to avoid copying all the members. It is great.

now Here is my problem.

I create a method

myMethod :: MyData Collect -> IO ()

but I want my method to work for MyData Collect and Mydata Caracterization but not Unchecked.

So It seems to me that I can not just do

myMethod :: MyData t -> IO ()


what is the right way to solve this problem ?


thanks for your help.


Frederic
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: phantom type

Francesco Ariis
On Sat, Mar 31, 2018 at 07:54:50AM +0000, PICCA Frederic-Emmanuel wrote:

> I create a method
>
> myMethod :: MyData Collect -> IO ()
>
> but I want my method to work for MyData Collect and Mydata Caracterization but not Unchecked.
>
> So It seems to me that I can not just do
>
> myMethod :: MyData t -> IO ()
>
>
> what is the right way to solve this problem ?

Hello Frederic,
    I am in a rush so I cant write a minimal example, but wouldn't
a typeclass + make Collect and Cara instances of that typeclass do?
-F
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: phantom type

Theodore Lief Gannon
Directly relevant blog: https://www.benjamin.pizza/posts/2017-12-15-functor-functors.html

On Sat, Mar 31, 2018, 1:41 AM Francesco Ariis <[hidden email]> wrote:
On Sat, Mar 31, 2018 at 07:54:50AM +0000, PICCA Frederic-Emmanuel wrote:
> I create a method
>
> myMethod :: MyData Collect -> IO ()
>
> but I want my method to work for MyData Collect and Mydata Caracterization but not Unchecked.
>
> So It seems to me that I can not just do
>
> myMethod :: MyData t -> IO ()
>
>
> what is the right way to solve this problem ?

Hello Frederic,
    I am in a rush so I cant write a minimal example, but wouldn't
a typeclass + make Collect and Cara instances of that typeclass do?
-F
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: phantom type

PICCA Frederic-Emmanuel
> Directly relevant blog: https://www.benjamin.pizza/posts/2017-12-15-functor-functors.html

thanks a lot very interesting post :)
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: phantom type

PICCA Frederic-Emmanuel
In reply to this post by Francesco Ariis
Hello

>     I am in a rush so I cant write a minimal example, but wouldn't
> a typeclass + make Collect and Cara instances of that typeclass do?

Yes I can do this in my case and it is not thaht difficult :).

thanks for your help.

cheers

Frederic
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners