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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:23:27+00:00 2026-06-08T14:23:27+00:00

First off I am using ghci under ubuntu 11.10 to run the haskell code.

  • 0

First off I am using ghci under ubuntu 11.10 to run the haskell code. 2nd this is my first attempts at haskell. Third, how might I load a file into ghci and where does it need to be located and what should its extension be? I know “:l “file.haskelxtnsn”” is how to load a file, but that’s my best guess so far.

Seeing as I can do the above, how does this code look for merging two list of possibly infinite size in ascending order. (I can’t put this in the prelude> prompt because of indentation???) Given [1, 2, 3] and [4, 5, 6] I should get [1, 2, 3, 4, 5, 6], and I think the usage would be “take 10 (merge listx listy)”

let merge x y = (min (head x) (head y)) : 
     case (min (head x) (head y)) of 
         head x -> merge (drop 1 x) y 
         head y -> merge x (drop 1 y)

psuedo:

  • output the min of the heads of the lists
  • if the first lists head was output call merge with the rest of the first list and the second
  • else call merge with the first list and the rest of the second list
  • 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-08T14:23:29+00:00Added an answer on June 8, 2026 at 2:23 pm
    • Usually the extension used is “.hs”.
    • You can use :cd in ghci to change directory, you can also supply a path to the :load (:l for short) command.
    • Your logic is correct, although maybe I’d write it a bit differently (hopefully you know about and where clause and defining a function as a series of equations):

      merge [] ys = ys
      merge xs [] = xs
      merge xs ys = min x y : if x < y then merge (tail xs) ys
                                       else merge xs (tail ys)
              where x = head xs
                    y = head ys
      
    • In ghci you need a let in front of definitions, which is different from the let ... in ... expression. This is rather confusing so I suggest you just put your code in a file and load it in ghci.
    • Function application has higher precedence then the : operator, so some of you parenthesis is not needed. We usually try to minimize the number of parenthesis to make the code more concise, but don’t be over zealous about it.
    • I don’t really see the point of using a case expression here (other than causing an error). Try reading on pattern matching for more detail, data constructors vs function applications, why you can’t use head x inside a pattern but you can do x:xs (Although I didn’t here). Calling head and min multiple times looks redundant, andy ou can also substitute drop 1 with tail.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Silverlight 4 and I'm experiencing the following problem: First off, the code:
First off I am using the Codeigniter Framework so this issue is a workaround
First off I'm using Mac. Next, I need to execute this "file.sh" we will
First off, I realize most of this can also be done using ItemTemplates. If
First off, I'm using Access 2000 and DAO. I have code that executes a
First off, I'm using OpenTK in a WPF application, but I think this is
First off, this might be the simplest questions on this site depending on the
First off, I'm using XCode 4.0.2. Okay, here is my issue. I can build
First off, I'm using the Qt 4 libraries and C++. Is there a way
First off I want to say that I am not using threads or multiple

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.