Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: section 1.10 #59

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Fix: section 1.10 #59

wants to merge 1 commit into from

Conversation

rachelcarmena
Copy link
Member

@rachelcarmena rachelcarmena commented Sep 4, 2019

⚠️

This is a draft PR
Please, I have a doubt and I need your help to finish it.

🏁

All the checks for 1.10 are OK with this PR.

📝

All the changes in this PR will be avoided with the use of the files in drafts directory for the next contributions:

  • Sorry, C++ code wasn't extracted for translation. Just Haskell code. So, this PR removes all the C++ code and the corresponding translations. I feel your pain...
  • Some snippets have been removed. See more reasons in this closed issue. I feel your pain again...

🆘

I need your help with this point.

When fixing this Haskell code:

length :: [a] -> Const Int a
length [] = Const 0
length (x:xs) = Const (1 + unConst (length xs))

I tried to fix the corresponding translation with the use of unConst which is defined later:

import arrow.typeclasses.Const
import arrow.typeclasses.fix
import arrow.core.extensions.const.semigroup.semigroup
import arrow.core.extensions.semigroup

tailrec fun <A> List<A>.length(acc: Const<Int, A> = Const.just(0)): Const<Int, Any?> =
  when (isEmpty()) {
    true -> acc
    false -> drop(1).length(
      Const.semigroup<Int, A>(Int.semigroup())
        .run { acc + Const.just<Int, A>(1) }.fix()
    )
  }
fun <A, T> Const<A, T>.unConst() = value()

However, I cannot find the way to use 'unConst' with the tail recursive function. unConst provides an integer and the accumulator has the type of Const.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant