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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:53:04+00:00 2026-05-25T14:53:04+00:00

I’m having trouble with pattern matching with lists in SML. I’m trying to create

  • 0

I’m having trouble with pattern matching with lists in SML. I’m trying to create a function that takes a 2×2 real matrix (defined as 'a list list) and creates a complex (real * real). The matrix is formatted as a list of lists(that are made with reals) with each list being a row. I know that I have to pattern match but I’m unsure how to implement my understanding into actual code. My code thus far is:

fun fromMatrix ((a::M):real matrix) : complex =  (hd a, tl M);

I keep getting this error:

stdIn:1.5-13.32 Error: right-hand-side of clause doesn't agree with function result type [tycon mismatch]
  expression:  real * real list list
  result type:  complex
  in declaration:
    fromMatrix =
      (fn <pat> :: <pat> : real matrix => (hd <exp>,tl <exp>): complex)
  • 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-25T14:53:05+00:00Added an answer on May 25, 2026 at 2:53 pm

    Okay so if (a::M) has type real matrix (or real list list), then that means a (head) has type real list and M (tail) has type real list list. Then hd a has type real, and tl M has type real list list. So putting them together, (hd a, tl M) has type real * real list list, probably not what you want.

    You probably want to understand that for lists, x :: y means that x is the first element, and y is the rest of the list (not the second element), which is a list. Similarly, the hd function returns the first element of a list, and the tl function returns the rest of the list. If you want to extract the first two elements, you could use the pattern x :: y :: z (where z is the rest of the list after the first 2 elements). If you know it’s going to be a 2-element list, you could match x :: y :: [], or equivalently, [x, y]. You can nest patterns, so if you have a 2-element list of 2-element lists, you could directly match [[a, b], [c, d]]. However, using a fixed-size list is a sign of bad design. You probably want to use a tuple instead.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace

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.