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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:14:17+00:00 2026-06-11T11:14:17+00:00

When compiling this: data Rec t = Rec { intPt :: t Int, doublePt

  • 0

When compiling this:

data Rec t = Rec { intPt :: t Int, doublePt :: t Double } deriving Show

type Pt2 a = (a,a)
type Pt3 a = (a,a,a)

type Rec2 = Rec Pt2 
type Rec3 = Rec Pt3

main = do
      print $ Rec (1,2) (3.4,5.6)
      print $ Rec (1,2,3) (5.6, 7.8, 9.0)   

I got

Unexpected type `t a' where type variable expected
In the declaration of `Rec (t a)'

How to make this compile and work?

  • 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-11T11:14:19+00:00Added an answer on June 11, 2026 at 11:14 am

    I cannot reproduce the exact error message you’re reporting, but I can see two issues with your example.

    1. You are trying to derive Show for Rec which is parameterized over a type constructor. This is too hard for GHC to do fully automatically at the moment, but you can make it work in practice by enabling a number of extensions.

    2. You are using partially applied type synonyms Pt2 and Pt3 as arguments to Rec, which isn’t permitted. You can work around this by switching to datatypes.

    A bit more detail: To solve problem 1, you can say:

    {-# LANGUAGE StandaloneDeriving, FlexibleContexts, UndecidableInstances #-}
    
    data Rec t = Rec { intPt :: t Int, doublePt :: t Double }
    deriving instance (Show (t Int), Show (t Double)) => Show (Rec t)
    

    By using a standalone deriving clause, you can explicitly specify the preconditions on the Show instance. In this case, these preconditions require the FlexibleContexts and UndecidableInstances extensions to also be enabled.

    To solve problem 2, you can do the following:

    data Pt2 a = Pt2 a a deriving Show
    data Pt3 a = Pt3 a a a deriving Show
    
    type Rec2 = Rec Pt2 
    type Rec3 = Rec Pt3
    

    Datatypes can be partially applied, but type synonyms cannot. So using Pt2 as an argument to Rec is only allowed if Pt2 is a datatype. With these modifications, your main function typechecks (and works):

    main = do
      print $ Rec (Pt2 1 2) (Pt2 3.4 5.6)
      print $ Rec (Pt3 1 2 3) (Pt3 5.6 7.8 9.0)   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I tried compiling program something like this with GCC: int f(int i){ if(i<0){
Compiling this code with g++ 4.7.0 ( -Wall -Wextra -Werror -Wconversion -std=c++11 ): #include
cout << boolalpha (1 < 0) << endl; I was compiling this recently as
Consider the following C program, 'pause.c': void main() { pause(); } Compiling this on
Why is this not compiling? error C2660: 'Concrete::WriteLine' : function does not take 1
I get an undefined reference to 'typeof'-error compiling and linking this: #include <stdio.h> #include
I get this error when compiling a C# application. Looks like a trivial error,
While compiling a program in Java I got this big WARNING warning: [unchecked] unchecked
This is the output I'm getting while compiling my class under Lubuntu 12.04 32bit
This morning in my CS lab, I was compiling and executing some C code.

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.