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 7671377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:02:24+00:00 2026-05-31T16:02:24+00:00

I understand the regular fixed-point type combinator and I think I understand the higher-order

  • 0

I understand the regular fixed-point type combinator and I think I understand the higher-order fixed-n type combinators, but HFix eludes me. Could you give an example of a set of data-types and their (manually derived) fixed points that you can apply HFix to.

  • 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-05-31T16:02:26+00:00Added an answer on May 31, 2026 at 4:02 pm

    The natural reference is the paper Generic programming with fixed points for mutually recursive datatypes
    where the multirec package is explained.

    HFix is a fixpoint type combinator for mutually recursive data types.
    It is well explained in Section 3.2 in the paper, but the idea is
    to generalise this pattern:

     Fix :: (∗ -> ∗) -> ∗
     Fix2 :: (∗ -> ∗ -> ∗) -> (∗ -> ∗ -> ∗) -> ∗
    

    to

     Fixn :: ((∗ ->)^n * ->)^n ∗
     ≈
     Fixn :: (*^n -> *)^n -> *
    

    To restrict how many types it does a fixed point over, they use type constructors
    instead of *^n. They give an example of an AST data type, mutually recursive over
    three types in the paper. I offer you perhaps the simplest example instead. Let
    us HFix this data type:

    data Even = Zero | ESucc Odd deriving (Show,Eq)
    data Odd  = OSucc Even       deriving (Show,Eq)
    

    Let us introduce the family specific GADT for this datatype as is done in section 4.1

    data EO :: * -> * where
      E :: EO Even
      O :: EO Odd
    

    EO Even will mean that we are carrying around an even number.
    We need El instances for this to work, which says which specific constructor
    we are refering to when writing EO Even and EO Odd respectively.

    instance El EO Even where proof = E
    instance El EO Odd  where proof = O
    

    These are used as constraints for the HFunctor instance
    for I.

    Let us now define the pattern functor for the even and odd data type.
    We use the combinators from the library. The :>: type constructor tags
    a value with its type index:

    type PFEO = U      :>: Even   -- ≈ Zero  :: ()      -> EO Even
            :+: I Odd  :>: Even   -- ≈ ESucc :: EO Odd  -> EO Even
            :+: I Even :>: Odd    -- ≈ OSucc :: EO Even -> EO Odd
    

    Now we can use HFix to tie the knot around this pattern functor:

    type Even' = HFix PFEO Even
    type Odd'  = HFix PFEO Odd
    

    These are now isomorphic to EO Even and EO Odd, and we can use the
    hfrom and hto functions
    if we make it an instance of Fam:

    type instance PF EO = PFEO
    
    instance Fam EO where
      from E Zero      = L    (Tag U)
      from E (ESucc o) = R (L (Tag (I (I0 o))))
      from O (OSucc e) = R (R (Tag (I (I0 e))))
      to   E (L    (Tag U))           = Zero
      to   E (R (L (Tag (I (I0 o))))) = ESucc o
      to   O (R (R (Tag (I (I0 e))))) = OSucc e
    

    A simple little test:

    test :: Even'
    test = hfrom E (ESucc (OSucc Zero))
    
    test' :: Even
    test' = hto E test
    
    *HFix> test'
    ESucc (OSucc Zero)
    

    Another silly test with an Algebra turning Even and Odds to their Int value:

    newtype Const a b = Const { unConst :: a }
    
    valueAlg :: Algebra EO (Const Int)
    valueAlg _ = tag (\U             -> Const 0)
               & tag (\(I (Const x)) -> Const (succ x))
               & tag (\(I (Const x)) -> Const (succ x))
    
    value :: Even -> Int
    value = unConst . fold valueAlg E
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand PCRE pretty well, but MySQL's regular expression flavor seems to get the
I understand basic regular expression, but unsure what the below quote means (regarding how
I don't understand what use local::lib does that regular use lib doesn't. Could someone
I understand that CDT 7 will have a regular expression error parser included, but
I understand regular expressions reasonably well, but I don't get to make use of
For some time I've been trying to understand regular expressions in JavaScript, but it
I think I understand the difference between ASCII mode and Binary mode on regular
I really don't understand regular expressions and was wondering what the following regular expressions
I understand, in a fuzzy sort of way, how regular ACID transactions work. You
I don't understand, why does the following regular expression: ^*$ Match the string 127.0.0.1?

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.