Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7840671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:52:04+00:00 2026-06-02T15:52:04+00:00

I’ve been reading about applicative functors, notably in the Functional Pearl by McBride and

  • 0

I’ve been reading about applicative functors, notably in the Functional Pearl by McBride and Paterson. But I’d like to solidify my understanding by doing some exercises. I’d prefer programming exercises but proof exercises are OK too.
What exercises will help me learn to program effectively with applicative functors?

Individual exercises are OK as are pointers to exercises listed elsewhere.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T15:52:07+00:00Added an answer on June 2, 2026 at 3:52 pm

    It seems amusing to post some questions as an answer. This is a fun one, on the interplay between Applicative and Traversable, based on sudoku.

    (1) Consider

    data Triple a = Tr a a a
    

    Construct

    instance Applicative Triple
    instance Traversable Triple
    

    so that the Applicative instance does “vectorization” and the Traversable instance works left-to-right. Don’t forget to construct a suitable Functor instance: check that you can extract this from either of the Applicative or the Traversable instance. You may find

    newtype I x = I {unI :: x}
    

    useful for the latter.

    (2) Consider

    newtype (:.) f g x = Comp {comp :: f (g x)}
    

    Show that

    instance (Applicative f, Applicative g) => Applicative (f :. g)
    instance (Traversable f, Traversable g) => Traversable (f :. g)
    

    Now define

    type Zone = Triple :. Triple
    

    Suppose we represent a Board as a vertical zone of horizontal zones

    type Board = Zone :. Zone
    

    Show how to rearrange it as a horizontal zone of vertical zones, and as a square of squares, using the functionality of traverse.

    (3) Consider

    newtype Parse x = Parser {parse :: String -> [(x, String)]} deriving Monoid
    

    or some other suitable construction (noting that the library Monoid behaviour for |Maybe| is inappropriate). Construct

    instance Applicative Parse
    instance Alternative Parse  -- just follow the `Monoid`
    

    and implement

    ch :: (Char -> Bool) -> Parse Char
    

    which consumes and delivers a character if it is accepted by a given predicate.

    (4) Implement a parser which consumes any amount of whitespace, followed by a single digit (0 represents blanks)

    square :: Parse Int
    

    Use pure and traverse to construct

    board :: Parse (Board Int)
    

    (5) Consider the constant functors

    newtype K a x = K {unK :: a}
    

    and construct

    instance Monoid a => Applicative (K a)
    

    then use traverse to implement

    crush :: (Traversable f, Monoid b) => (a -> b) -> f a -> b
    

    Construct newtype wrappers for Bool expressing its conjunctive and disjunctive monoid structures. Use crush to implement versions of any and all which work for any Traversable functor.

    (6) Implement

    duplicates :: (Traversable f, Eq a) => f a -> [a]
    

    computing the list of values which occur more than once. (Not completely trivial.) (There’s a lovely way to do this using differential calculus, but that’s another story.)

    (7) Implement

    complete :: Board Int -> Bool
    ok :: Board Int -> Bool
    

    which check if a board is (1) full only of digits in [1..9] and (2) devoid of duplicates in any row, column or box.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.