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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:00:15+00:00 2026-05-23T00:00:15+00:00

Given the following type definition: type ‘a range = Full | Range of (‘a

  • 0

Given the following type definition:

type 'a range = Full | Range of ('a * 'a);;

How do I convert values of this type to strings?

I currently have:

let string_of_range r = match r with
  | Full -> "Full"
  | Range(a,b) -> "Range("^(string_of_int a)^","^(string_of_int b)^")";; 

But of course, this says that a and b are of type int. They could also be floats or chars (see my previous question about constraining the type)

  • 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-23T00:00:16+00:00Added an answer on May 23, 2026 at 12:00 am

    Change your function to accept a string converter and use it in your implementation. Then when you call it, pass in an appropriate converter and range. Something like:

    let string_of_range str_conv = function
      | Full -> "Full"
      | Range(a, b) -> "Range (" ^ (str_conv a) ^ ", " ^ (str_conv b) ^ ")"
    

    It will have the type: string_of_range : ('a -> string) -> 'a range -> string

    Example call:

    string_of_range string_of_int (Range (1, 2))
    

    Ordered this way, you could easily make more specialized converters.

    let string_of_int_range = string_of_range string_of_int
    

    It will have the type: string_of_int_range : int range -> string

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

Sidebar

Related Questions

I have a table FOO with the following definition: id INTEGER, type INTEGER, data
We have a WSDL which contains the following type definition: ... <xsd:complexType name=OrderItem> <xsd:all>
Given the following example, why do I have to explicitly use the statement b->A::DoSomething()
Given a function prototype, and a type definition: int my_function(unsigned short x); typedef unsigned
given the following class definition: public class Order { public IProduct Product {get;set;} }
I tried the following: let inline (|OpAdd|_|) (aty:Type, x:obj, y:obj) = if aty.Equals(typeof<'a>) then
Given the following CRTP type in C#: public abstract class DataProviderBase<TProvider> where TProvider :
Setup Given this user-defined type: struct T { static int x; int y; T()
Consider following function definition in ghci. let myF = sin . cos . sum
Given the following Scala definitions abstract class C { type T1 <: { def

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.