Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Haskell function implementing

I have next data type:

newtype Fun i a = F (i -> a)

And I have to implement function with next signature:

joinFun :: Fun i (Fun i a) -> Fun i a

I tried

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

joinFun (F f) = f

but it have type i -> Fun i a
How can I implement this function with right types?

>Solution :

f has as type i -> Fun i a, and you are supposed to return a Fun i a, so a function that maps an i to an a.

The only sensical thing to do is construct a function that takes a parameter of type i, that will be used on f, this will then return a Fun i a, where we will evaluate that function by applying it again with that parameter i.

We thus can implement joinFun with:

joinFun :: Fun i (Fun i a) -> Fun i a
joinFun (F f) = F go
    where go i = case f i of
              (F g) -> …

where I leave implementing the part as an exercise.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading