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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:35:22+00:00 2026-05-27T14:35:22+00:00

How do I say Haskell to interpret something as a special type? For example,

  • 0

How do I say Haskell to interpret something as a special type?
For example, I have a list and want to divide its length by 2.
So I write

(length mylist) / 2

and get this error

No instance for (Fractional Int)
arising from a use of `/’

As I want a whole-number division, I’d like to make length mylist, 2 and the result Int.

  • 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-27T14:35:23+00:00Added an answer on May 27, 2026 at 2:35 pm

    There are two different issues here.

    • Integer division: Use the div function : div (length mylist) 2 or (length mylist) `div` 2

    • Casting. One can tell Haskell that a particular expression has a particular type by writing expression :: type instead of just expression. However, this doesn’t do any “casting” or “conversion” of values. Some useful functions for converting between various numeric and string types are fromIntegral, show, read, realToFrac, fromRational, toRational, toInteger, and others. You can look these up on Hoogle.

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

Sidebar

Related Questions

How do I print a list to stdout in Haskell? Let's say I have
So let's say you have a variable n. You want to check if its
Say I have three files (template_*.txt): template_x.txt template_y.txt template_z.txt I want to copy them
Let's say we have the following Haskell: data T = T0 | T1 |
Say I want to know if F# has a library function of type ('T
I'm struggling with Haskell programming. I've got the list below and I want to
In Haskell, I'd like to generate a list of random integers of undetermined length.
Let's say I want to generate a random number in Haskell. To do so,
Is there some Haskell function that can take a list, say of doubles, like
Type inference in Haskell has a bit of a learning curve (to say the

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.