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

  • Home
  • SEARCH
  • 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 8151219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:18:30+00:00 2026-06-06T15:18:30+00:00

This is the code (Euclid’s algorithm for GCD). Of course there is Prelude.gcd but

  • 0

This is the code (Euclid’s algorithm for GCD). Of course there is Prelude.gcd but as an exercise I am implementing my own.

selfGCD :: Integral f => f -> f -> f  
selfGCD a b = if b == 0 then
        return a
    else 
        return (selfGCD a (mod a b))

Using ghci, I get the following error:

two.hs:32:25:  
Couldn't match type `f' with `m0 f'  
  `f' is a rigid type variable bound by  
      the type signature for selfGCD :: Integral f => f -> f -> f  
      at two.hs:31:1  
In the return type of a call of `return'  
In the expression: return a  
In the expression:  
  if b == 0 then return a else return (selfGCD a (mod a b))  

two.hs:34:25:  
Couldn't match type `f' with `m1 f'  
  `f' is a rigid type variable bound by  
      the type signature for selfGCD :: Integral f => f -> f -> f  
      at two.hs:31:1  
In the return type of a call of `return'  
In the expression: return (selfGCD a (mod a b))  
In the expression:  
  if b == 0 then return a else return (selfGCD a (mod a b))  

How can I rectify the problem?

  • 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-06T15:18:32+00:00Added an answer on June 6, 2026 at 3:18 pm

    Drop the returns.

    In Haskell, return is a function of type

    return :: Monad m => a -> m a
    

    and not the return operator you know from imperative languages.

    Thus with the returns, the implementation has type

    selfGCD :: (Integral a, Monad m) => a -> a -> m a
    

    contrary to the type signature.

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

Sidebar

Related Questions

This code used to return my local ip address as 192.xxx.x.xxx but now it
This code won't compile because there is an illegal reference to a static field.
This code is ment to download the source code of an html file but
This code is reading from mysql db tables and should return few names. But
This code runs perfectly on Java but when I run this on Android platform,
This code should works, but in fact the span is not displayed : <a
This code all works, but I'm basically blundering around my lack of knowledge in
This code below works fine in Chrome and IE 9. But breaks in IE
This code works fine for FF, Safari, Chrome and IE9, but doesn't work 100%
This code works fine in <= IE7, but it doesn't work in firefox ..

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.