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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:33:32+00:00 2026-05-20T23:33:32+00:00

I am trying to define a new type of data, to create a list

  • 0

I am trying to define a new type of data, to create a list and then to create a stream out of the list:

type 'a myType =  Name of char ;;
let myList = [Name('a')];;
let myStream = Stream.of_list myList;;

Error: The type of this expression, ‘_a myType Stream.t,
contains type variables that cannot be generalized

Any idea?

  • 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-20T23:33:32+00:00Added an answer on May 20, 2026 at 11:33 pm

    In your code, myStream is a stream of type myType parametrized by an unknown type (which is called '_a in your error above). The compiler did not find enough information in your code about what '_a should be.

    In some cases, the compiler would then generalize the type by stating that '_a can be anything. For instance, myList is properly identified as 'a myType list. However, given that Stream.t is an abstract type, generalization might cause errors, so it is not performed.

    One way to work around this is to specify the type of '_a if you only intend it to be used with a single type, for instance with a type constraint :

    let myStream : int myType Stream.t = ...
    

    Another way, if you wish to keep it generic, is to turn it into a function (which is then automatically generalized) :

    let myStream () = Stream.of_list myList
    

    The type will be unit -> 'a myType Stream.t as expected.

    The underlying reason why such generalization might cause errors is the presence of mutable state. Suppose that I define four files as such:

    (* ref.ml *)
    let x = ref None
    
    (* ref.mli *)
    val x : 'a option ref
    
    (* a.ml : 'a = string *)
    Ref.x := Some "Hello"
    
    (* b.ml : 'a = int *)
    match !ref x with None -> () | Some i -> print_int i
    

    This would cause a runtime error. As such, whenever mutable state is involved, types cannot be generalized.

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

Sidebar

Related Questions

What I'm trying to do is create a new custom data type that behaves
I'm trying to define a new type and have not had much luck finding
I'm trying to define a new shortcode in WordPress, and I get the following
I'm trying to define a new URL handler under OSX that will point at
I'm using eclipse + android SDK. I'm trying to create a table with data
I am trying to using Netsuite's PHPtoolkip_v2010.php to add new customer records and define
Im trying to loop a array with extjs xtemplate and create a table Ext.define('dataview_model',
Im trying to define a dataTemplate for a business object in my wpf application
I'm trying to define a task that emits (using echo) a message when a
I'm trying to define a table to store student grades for a online report

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.