Comments (7)
It seems like the return type of your poly()
is AnyVal
, which suggests a possible bug in the poly()
function.
from chisel-bootcamp.
yes that makes sense, Ive found the problem: in the former scala numeric exercise, I used "if(select==0)else if(select==1)else if(select==2)" instead of "if(select==0)else if(select==1)else ..." to do the conditional branch. it works now. but it seems not a problem of the return type of poly() ? To be honest I suppose "if(select==0)else if(select==1)else if(select==2)" and "if(select==0)else if(select==1)else ..." have almost no difference in this case, isn't it? even it fixes the problem, I still don't know why...moreover, in the former use of the function expect, expect(IO, val) is often the case.
from chisel-bootcamp.
If you define a function that returns in some branches, not others, Scala will infer the result type to be AnyVal
. For example:
def funcTest(sel: Int) = {
if (sel == 5) {
10
}
}
is equivalent to:
def funcTest(sel: Int): AnyVal = {
if (sel == 5) {
10
}
}
from chisel-bootcamp.
emm, I see. so that means:
a) the type AnyVal != Val
b) if the conditions listed are not complete the function will be defined as AnyVal defaultly, instead of a normal Val.
correct?
from chisel-bootcamp.
a) Val
is not a Scala type and lowercase val
is a keyword and cannot be used as a variable name
b) The return type if none of the if conditions are triggered is Unit
, and Scala will determine the result type to be the common supertype of the branch (Int
) and Unit
, which is AnyVal
. Note that AnyVal
is much less useful and should generally be avoided. If you need to sometimes return a type, Scala has the Option type.
In other words:
def funcTest(sel: Int): AnyVal = {
if (sel == 5) {
10
}
}
is identical to:
def funcTest(sel: Int): AnyVal = {
if (sel == 5) {
10
} else {
Unit
}
}
from chisel-bootcamp.
I believe this time I get it~thats really helpful!
thanks for your patience!
from chisel-bootcamp.
Glad to hear it!
from chisel-bootcamp.
Related Issues (20)
- Fix 3.6 TypeSafe section HOT 1
- 2.6: `DecoupledGcd` example is not decoupled on the output side and tests fail to catch it
- ammonite.util.CompilationError: Failed to resolve ivy dependencies:Error downloading edu.berkeley.cs:chisel3_2.13:3.2.0 HOT 4
- how to save the dependent libraries in the local Machine HOT 2
- Failed to resolve ivy dependencies:/coursier_cache/.structure.lock (Permission denied) HOT 4
- 2.3_control_flow Reference io is not fully initialized. HOT 1
- java.nio.charset.MalformedInputException: Input length = 1 HOT 5
- cmd10.sc:12: reference to Data is ambiguous; HOT 2
- the tester in "2.5_exercise.ipynb" for example "DSPBlock" is old test framework
- 3.2 interlude: arbiter never asserts "ready" for inputs
- Chapter 3.3 - excercise on decoupled arbiter is confusing
- Chapter 3.6 - companion object for Mac: solution for apply(..) is not a Factory method HOT 2
- Write a "How to contribute" section to the README
- Module 2.5 - DspBlock - not found: type PeekPokeTester HOT 1
- the direction of <> operator in Chisel? in 2.6 chiseltest HOT 1
- doubt about 2.6 Chiseltest HOT 2
- can not run 2.1 locally HOT 6
- value step is not a member of chisel3.Clock in 3.2 HOT 4
- I have a question about scala grammar in 3.6
- I have some question about module 3 Interlude: Chisel Standard Library
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chisel-bootcamp.