Questions tagged [monomorphism]

monomorphism is a property of a programming language which sets a default type if there is no type specified, and coerces to a new type based on the later usage of the variable

Monomorphism is the opposite of polymorphism, which means that it morphs an untyped object to a single type.

References

16 questions
27
votes
2 answers

Why do monomorphic and polymorphic matter in JavaScript?

I've been reading some articles on change detection, and all of them say that monomorphic functions are much faster than polymorphic. For example, here is a quote: (..)The reason for that is, that it has to be written in a dynamic way, so it can…
uksz
  • 18,239
  • 30
  • 94
  • 161
19
votes
3 answers

why polymorphism is so costly in haskell(GHC)?

I am asking this question with refernce to this SO question. Accepted answer by Don stewart : First line says "Your code is highly polymorphic change all float vars to Double .." and it gives 4X performance improvement. I am interested in doing…
fedvasu
  • 1,232
  • 3
  • 18
  • 38
13
votes
4 answers

What's the Difference Between Subgraph Isomorphism and Subgraph Monomorphism?

In one of the projects I've worked on, the subject of isomorphism versus monomorphism came up. A little background: I'm no expert on graph theory and have no formal training in it. But this topic is very important in chemistry, where chemists expect…
Rich Apodaca
  • 28,316
  • 16
  • 103
  • 129
10
votes
1 answer

Does julia perform code monomorphization for recursively polymorphic types?

I've noticed that implementing polymorphic recursive types in languages that perform code monomorphization (for e.g: C++, Rust, etc.) is very difficult, if not impossible. This is usually because the compiler needs to generate code for every…
4
votes
1 answer

Basic Haskell monomorphism/polymorphism question (HList)

I'm a Haskell and a Stackoverflow noob, and here's my first & probably quite basic Haskell question. module M where import Data.HList data R r a r1 = undefined :: R a Int r2 = undefined :: R a Double rPair :: R r a -> R r b -> (R r a, R r…
polypus74
  • 429
  • 4
  • 8
3
votes
1 answer

Avoiding monomorphism in let bindings without type annotation

I've got some code using types to disambiguate instances (the real code is using GHC.TypeLits singletons for type tags, but I don't think that's germane) and I'd like to use a let binding to avoid text-level duplication; unfortunately, this…
Alex R
  • 2,201
  • 1
  • 19
  • 32
2
votes
2 answers

Retrieve some meta information from the arbitrary JavaScript object monomorphically (v8)?

Question for v8 experts. Recently, I've discovered the situation with polymorphism in v8. It is that polymorphism is well-optimized only up to the 4 object "shapes", after which the performance degrades significantly. Classes and object inheritance…
1
vote
2 answers

Why does F# function return a signature of "val FunctionName: int -> int"?

I was following some examples on F# Wikibook on High Order Functions. Second code snippet under title, Composition Function has following code snippet. #light open System let compose f g x = f (g x) let xSquared x = x*x let negXPlusFive x = -x/2.0…
dance2die
  • 35,807
  • 39
  • 131
  • 194
1
vote
2 answers

Haskell Implicit parameters and polymorphic recursion

I have a question on "Implicit parameters and polymorphic recursion" chapter of GHC User Guide. The code is len1 :: [a] -> Int len1 xs = let ?acc = 0 in len_acc1 xs len_acc1 [] = ?acc len_acc1 (_:xs) = let ?acc = ?acc + (1::Int) in len_acc1…
amakarov
  • 524
  • 3
  • 16
1
vote
1 answer

Using monomorphic functions with polymorphic Haxl library?

I'm using the Haxl library and I'm trying to implement fetchHTML concurrently: import Data.Aeson import Control.Concurrent.Async import Control.Concurrent.QSem import Haxl.Core import Haxl.Prelude instance DataSource' u HTTPRequest where fetch =…
Babra Cunningham
  • 2,949
  • 1
  • 23
  • 50
1
vote
2 answers

Monomorphic type in pattern matching with default case

Well, actually it's not a problem since I solved it but it bothers me too much : Let's write this : test.ml type bop = Beq | Bneq | Badd type value = Vint of int | Vchar of char let eval bop a b = let op = match bop with | Beq -> (=) …
Lhooq
  • 4,281
  • 1
  • 18
  • 37
0
votes
1 answer

Rust - can I ask/force compiler to do monomorphization code generation while compiling a crate (instead of postponing it to the caller crate )

I have project that build with cargo workspace with including lot of crates. One of the lower level crates contains generic data-structure with a lot of serde-code involved. In order to reduce the compile time , I tried to crate objects with…
Eyal leshem
  • 995
  • 2
  • 10
  • 21
0
votes
1 answer

Why am I able to write a function type in the type parameter of a struct?

If I understand correctly, in Rust every closure type has a unique type that cannot be written out. I also thought this applied to functions, however, I'm able to do the following, in which I explicitly write the type parameter in the return types…
Harry Braviner
  • 627
  • 4
  • 12
0
votes
1 answer

Algorithm W and monomorphic type coercion

I'm trying to write my own type inference algorithm for a toy language, but I'm running into a wall - I think algorithm W can only be used for excessively general types. Here are the expressions: Expr ::= EAbs String Expr | EApp Expr Expr …
Athan Clark
  • 3,886
  • 2
  • 21
  • 39
0
votes
1 answer

overgeneralized curried fns

module MapHelpers (Ord : Map.OrderedType) = struct include Map.Make (Ord) let add_all a b = fold add a b end works but the seemingly equivalent module MapHelpers (Ord : Map.OrderedType) = struct include Map.Make (Ord) let add_all = fold…
Mike Samuel
  • 118,113
  • 30
  • 216
  • 245
1
2