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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:50:39+00:00 2026-06-05T07:50:39+00:00

As a simple exercise to get me acquainted with Haskell, after idling around on

  • 0

As a simple exercise to get me acquainted with Haskell, after idling around on Youtube and stumbling into the American Countdown game show, I wanted to make a solver for the Numbers game.

You get 6 numbers and need to combine them with (+) (-) (*) (/) in order to get a given result.

enter image description here

What I’ve got so far is the very brain-dead,

let operands = [75, 2, 6, 3, 8, 7] :: [Double]
let goal = 623 :: Double
let operations = [(+), (-), (*), (/)]

show (head [(a, x, b, y, c, z, d, t, e) |
      a <- operands,
      b <- filter (\ q -> q /= a) operands,
      c <- filter (\ q -> q /= a && q /= b) operands,
      d <- filter (\ q -> q /= a && q /= b && q /= c) operands,
      e <- filter (\ q -> q /= a && q /= b && q /= c && q /= d) operands,
      x <- operations,
      y <- operations,
      z <- operations,
      t <- operations,
      t (z (y (x a b) c) d) e == goal])

…but obviously Show doesn’t know what to do with functions.

No instance for (Show (Double -> Double -> Double))
  arising from a use of `show'
Possible fix:
  add an instance declaration for (Show (Double -> Double -> Double))

How can I work around this? Do I need to mess with type and data constructors to make my own functions that can print or is there some easier way around it?

  • 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-05T07:50:41+00:00Added an answer on June 5, 2026 at 7:50 am

    I would generally not advise you to implement a Show instance for functions. It is not the “haskelly” way of doing things, for this reason:

    You define a “canonical” way of showing functions. You might want them to be shown as their names now, but what if you decide to do this:

    add 0 y = y
    add x y = add (x - 1) (y + 1)
    
    operations = [..., add, ...]
    

    Should really the output of your program change depending on your internal implementation? That doesn’t make much sense. Also, what happens to nameless functions?

    Also, in another part of the program, you might want to show your functions as their types instead, etc., and then you’d have conflicting Show instances.

    Generally, only implement Show when you know that there should be only one way of showing that thing, and that that way works for all values that need to be shown.


    The simplest way of solving this problem would probably be to just store the name of the operation along with the operation. Like so:

    let operations = [("+", (+)), ("-", (-)), ("*", (*)), ("/", (/))]
    
    -- ...
    show (head [(a, xname, b, yname, c, zname, d, tname, e) |
      a <- operands,
      b <- filter (\ q -> q /= a) operands,
      c <- filter (\ q -> q /= a && q /= b) operands,
      d <- filter (\ q -> q /= a && q /= b && q /= c) operands,
      e <- filter (\ q -> q /= a && q /= b && q /= c && q /= d) operands,
      (xname, x) <- operations,
      (yname, y) <- operations,
      (zname, z) <- operations,
      (tname, t) <- operations,
      t (z (y (x a b) c) d) e == goal])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It's an exercise of EF code-first. There's a simple method. I want to get
I am creating a very simple game in AS3 as an exercise in pure
As a small exercise I am trying to write a very small, simple game
I have a simple exercise where I call a Thread and subsequently the run()
I'm trying to do a simple exercise querying a database from JS using XMLHTTPrequest
I'm working on building a pretty simple site mainly as an exercise in learning
I want to write a simple web proxy, for exercise. Here's the code I
I'm writing a small interpreter for a simple BASIC like language as an exercise
I'm starting to learn C++ and as an exercise decide to implement a simple
so I'm making some basic programming language (just for exercise). I've made simple grammar

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.