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

  • Home
  • SEARCH
  • 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 5929133
In Process

The Archive Base Latest Questions

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

OK, i’m used to good old C assertions, when they fail they output the

  • 0

OK, i’m used to good old C assertions, when they fail they output the condition they failed on, and the line it was on. (implimented with the preprocessor).

Now I’m programming in F# (a .net language), got code full of assert. (trying to program defensivly). and my assets show a popup with the call stack. according to the documentation could also pass the assert a string to display when it fails. so i could make it pass a string copy of my condition. eg:

assert (x=true, "x=true")

but this violate the Duplication (avoiding) principal.

If I later decide to change what I want to assert. (maybe i realised i was asserting something to be false when i should have been asserting it to be true) then I have to change the code in two places, otherwise the message won’t match what I’m actually checking. and if i forget things could be really confusing.

How is this normally dealt with?

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

    Echoing what Tomas said, you can use quotations to avoid duplication. But instead of ToLinqExpression -> ToString, which apparently produces C# source code, you can use my library Unquote which produces F# source code strings. Combine this with an implementation suitable for production code (i.e. defining Assert inline with a non-DEBUG compilation symbol branch emitting only the no-op () means uses of Assert will be completely removed in non-DEBUG builds with optimizations turned on):

    let inline Assert (q:Expr<bool>) =
        #if DEBUG
            System.Diagnostics.Debug.Assert(q.Eval(), q.Decompile())
        #else
            ()
        #endif
    

    then the assertion expression Assert <@ (22 + 2) / 2 = ("assert" |> String.length) @> produces the following popup dialog by default (I think you can configure System.Diagnostics.Debug behavior):

    enter image description here

    Where in comparison q.ToLinqExpression().ToString() produces (((22 + 2) / 2) == op_PipeRight("assert", ToFSharpFunc(str => Length(str)))).

    In fact, Unquote was designed specifically for the purpose of producing helpful unit test assertion failure messages, and can easily be adapted to debug assertions producing step-by-step failure messages:

    let inline Assert (q:Expr<bool>) =
        #if DEBUG
            System.Diagnostics.Debug.Assert(q.Eval(), q.ReduceFully() |> List.map (fun q -> q.Decompile()) |> String.concat System.Environment.NewLine)
        #else
            ()
        #endif
    

    enter image description here

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

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am using Paperclip to handle profile photo uploads in my app. They upload
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.