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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:26:38+00:00 2026-06-18T00:26:38+00:00

I have this SML code. I don’t know why I cannot compile this :

  • 0

I have this SML code. I don’t know why I cannot compile this :

fun score = 
    let
       val sum = 3; (* error at this line : SYNTAX ERROR : inserting LPAREN *)
       if sum div 2 > 0
       then sum = 0
       else sum = 1
       (*some other code*)
    in
       sum (* I want to return sum after some steps of calculation *)
    end
  • 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-18T00:26:39+00:00Added an answer on June 18, 2026 at 12:26 am

    There are more issues with your code, than jacobm points out.
    You are also missing a function argument. Functions in SML always takes one argument. For example

    fun score () = 
        let val sum = 3
            val sum = if sum div 2 > 0
                      then sum = 0
                      else sum = 1
        in
           sum
        end
    

    However this still doesn’t make much sense. since the expressions sum = 0 and sum = 1 evaluates to a Boolean.

    A let-expression is used to make some local declarations which are only visible inside the in ... end part. Thus the calculations you wan’t to do with sum, should probably be done inside the in ... end part, unless you wan’t to express it as a means of a function.

    One such example is

    fun score () = 
        let val sum = 3
        in
          if sum div 2 > 0
          then ...
          else ...
        end
    

    If we look at the syntax of a let-expression, it probably makes more sense

    let
      <declaration>
    in
      <expr> ; ... ; <expr>
    end
    

    Since if-then-else is an expression, it can’t be in the “declarations part” by itself.

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

Sidebar

Related Questions

I have this code: fun all_except_option2(str : string, strlst : string list) = let
I have the following SML code that I wrote for a class: fun lookup
I have this snippet of the code in ML: local fun unfolder( [] ,
I have this bit of code: fun foldr2(f, x::xs) = if xs = []
Have this query: SELECT count(*) as Total, SUM(CASE WHEN gender = 1 then 1
Recently I have started dabbling in the sml-mode Emacs package for running SML code.
I have been checking this code for ages trying to find the cause of
Have this bit of code in my app... Request::instance()->directory After upgrading to 3.1 it
have this code: template<typename T, template<typename, typename> class OuterCont, template<typename, typename> class InnerCont, class
have this code: $products = $feed->_xpath->query( //cf:vehicle ); foreach( $products as $product ) {

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.